Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

1 like 0 dislike
212 views
in Selenium by
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("mnm123HARMON!@#");
driver.findElement(By.xpath("//*[@id=\"renderForm\"]/div[1]/div[8]/label"));
driver.findElement(By.xpath("//*[@id=\"1000_1000_1000_1003_Confirm Password\"]")).sendKeys("mnm123HARMON!@#");
driver.findElement(By.xpath("//*[@id=\"renderForm\"]/div[2]/div/button[1]")).click();
}
}

2 Answers

1 like 0 dislike
by
selected by
 
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

by The go-to Tester (181 points)
Glad that worked for you.
0 like 0 dislike
by The go-to Tester (181 points)
What point you're getting exception? Can you post your stacktrace?


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

1.4k questions

1.6k answers

866 comments

1.9k users

...