power_settings_new

NoSuchElementfound Exception

by
asked
+1 vote
47 views
public class MyClass1  {
 
public static void main(String[] args) throws InterruptedException,IOException{
 
System.out.println("*******************");
System.out.println("launching chrome browser");
System.setProperty("webdriver.chrome.driver", "C://Users/admin/Downloads/chromedriver_win32/chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.manage().window().maximize();
int x=0;
    File file =    new File("C:\\users\\admin\\EminentIT\\ue.xlsx");
 
FileInputStream inputStream = new FileInputStream(file);
 
Workbook ueWorkbook =  null;
String username= "";
String email   = "";
 
String fileExtensionName = "ue.xlsx".substring("ue.xlsx".indexOf("."));
 
    //Check condition if the file is xlsx file
 
    if(fileExtensionName.equals(".xlsx")){
 
    //If it is xlsx file then create object of XSSFWorkbook class
 
    ueWorkbook = new XSSFWorkbook(inputStream);
 
    }
 
    //Check condition if the file is xls file
 
    else if(fileExtensionName.equals(".xls")){
 
        //If it is xls file then create object of XSSFWorkbook class
 
        ueWorkbook = new HSSFWorkbook(inputStream);
 
    }
   
Sheet ueSheet = ueWorkbook.getSheet("Sheet1");
 
Iterator<Row> itr = ueSheet.iterator();
 
// Iterating over Excel file in Java 
 
while (itr.hasNext()) { 
Row row = itr.next(); 
// Iterating over each column of Excel file 
Iterator<Cell> cellIterator = row.cellIterator();
while (cellIterator.hasNext()) { 
Cell cell = cellIterator.next();
 
switch (cell.getCellType()) {
case Cell.CELL_TYPE_STRING: 
//System.out.print(cell.getStringCellValue() + "\t");
username = cell.getStringCellValue();
cell = cellIterator.next();
email    = cell.getStringCellValue();
System.out.println(username);
System.out.println(email);
if (x == 0)
{
 
 
JavascriptExecutor je15 = (JavascriptExecutor)driver;
je15.executeScript("arguments[0].scrollIntoView(true);",driver.findElement(By.xpath("//*[@id=\"rvmp-home-nav\"]/li[2]/a")));
driver.findElement(By.xpath("//*[@id=\"rvmp-home-nav\"]/li[2]/a")).click();
 
JavascriptExecutor je = (JavascriptExecutor)driver;
je.executeScript("arguments[0].scrollIntoView(true);",driver.findElement(By.id("developer")));
            
driver.findElement(By.id("developer")).click();
}
else
{
driver.findElement(By.xpath("//*[@id=\"renderForm\"]/div[3]/a")).click();
 
JavascriptExecutor je = (JavascriptExecutor)driver;
je.executeScript("arguments[0].scrollIntoView(true);",driver.findElement(By.id("developer")));
            
driver.findElement(By.id("developer")).click();
}
 
driver.findElement(By.xpath("//*[@id=\"renderForm\"]/div[1]/div[1]/label"));
driver.findElement(By.id("first_name")).sendKeys("Udayarajan");
 
driver.findElement(By.xpath("//*[@id=\"renderForm\"]/div[1]/div[2]/label"));
driver.findElement(By.id("last_name")).sendKeys("Gauthaman");
 
driver.findElement(By.xpath("//*[@id=\"renderForm\"]/div[1]/div[3]/label"));
//driver.findElement(By.id("pricing1")).();
 
driver.findElement(By.xpath("//*[@id=\"renderForm\"]/div[1]/div[4]/label"));
driver.findElement(By.id("phone")).sendKeys("9176056472");
driver.findElement(By.xpath("//*[@id=\"renderForm\"]/div[1]/div[5]/label"));
driver.findElement(By.xpath("//*[@id=\"1000_1000_1000_1000_User Name\"]")).clear();
driver.findElement(By.xpath("//*[@id=\"1000_1000_1000_1000_User Name\"]")).sendKeys(username);
driver.findElement(By.xpath("//*[@id=\"renderForm\"]/div[1]/div[6]/label"));
//*[@id="1000_1000_1000_1001_Email Address"]
driver.findElement(By.xpath("//*[@id=\"1000_1000_1000_1001_Email Address\"]")).sendKeys(email);
driver.findElement(By.xpath("//*[@id=\"renderForm\"]/div[1]/div[7]/label"));
driver.findElement(By.xpath("//*[@id=\"renderForm\"]/div[1]/div[7]/label/a"));
driver.findElement(By.id("1000_1000_1000_1002_Password")).sendKeys("[email protected]#");
driver.findElement(By.xpath("//*[@id=\"renderForm\"]/div[1]/div[8]/label"));
driver.findElement(By.xpath("//*[@id=\"1000_1000_1000_1003_Confirm Password\"]")).sendKeys("[email protected]#");
driver.findElement(By.xpath("//*[@id=\"renderForm\"]/div[2]/div/button[1]")).click();
}
}

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.

2 Answers

answered by
selected by
+1 vote
 
Best answer

Hi Guys

 

   I got the answer to this question.It is related to the logic of the program and not a general concept to understand.

I inserted another Cell cell = cellIterator.next();   next to the present one and it worked.

 

Thanks you very much

Regards

Uday

commented by (171 points)
Glad that worked for you.
answered by (171 points)
0 votes
What point you're getting exception? Can you post your stacktrace?
add
...