I need help with my automation script.
First I need to click add button so it will open device id and device name text box. I am passing a value to that text box from excel sheet using filo and clicking on save. I am reading data from excel sheet. For any existing value, it will fetch data from excel sheet one by one. But if I enter new data in the sheet and try to fetch it will throw an error
element not visible
This is my script:
public void Click_Smart_Cart_Button() throws IOException, FilloException, InterruptedException
{
System.out.println(".....Click operation on Add_Smart_Cart_Device button......");
WebElement smart_cart_btn=driver.findElement(By.xpath(rx.readdatafromexcel("sheet1", 1,1)));
WebDriverWait wait2=new WebDriverWait(driver,15);
wait2.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(rx.readdatafromexcel("sheet1",1,1))));
mod.click(smart_cart_btn);
System.out.println(" ");
System.out.println("....Button is clicked Successfully....");
System.out.println(" ");
// Operation to Retrieve data from the Excel Sheet "TestData"
Fillo fillo= new Fillo();
Connection con=fillo.getConnection(Filepath);
String query = "Select SmartCartDeviceID, SmartCartDeviceName from Sheet1";//the parameters name and column name in excel sheet must be same.Eg "username"
Recordset results= con.executeQuery(query);
while(results.next()){
//Click on Device id text box and send data from sheet
System.out.println("....Click operation on Smart Card Device id text box....... ");
System.out.println(" ");
WebElement click_id_box=driver.findElement(By.xpath(rx.readdatafromexcel("sheet1", 2,1)));
if(click_id_box.isDisplayed()==false)
{
driver.manage().timeouts().implicitlyWait(6, TimeUnit.SECONDS);
mod.click(smart_cart_btn);
}
mod.click(click_id_box);
System.out.println("......Smart card device id box is clicked Sucessfully.....");
System.out.println(" ");
System.out.println("....Checking whther the id box field is empty or not...");
System.out.println(" ");
if(click_id_box != null)
{
click_id_box.clear();
}
click_id_box.sendKeys(results.getField("SmartCartDeviceID"));
Thread.sleep(1000);
System.out.print("Device id is "+results.getField("SmartCartDeviceID") +" ");
System.out.println(" ");
System.out.println("......Device id is sent succefully from the excel sheet.....");
System.out.println(" ");
//Click on Device name text box and send data from the sheet
System.out.println(".....Click operation on Smart Card Device Name Text Box...");
System.out.println(" ");
WebElement click_name_box=driver.findElement(By.xpath(rx.readdatafromexcel("sheet1", 3,1)));
mod.click(click_name_box);
System.out.println("......Smart Cart Device id box is clicked Successfully....");
System.out.println(" ");
System.out.println("....Checking whther the Device name box field is empty or not.....");
System.out.println(" ");
if( click_name_box!=null)
{
click_name_box.clear();
}
click_name_box.sendKeys(results.getField("SmartCartDeviceName"));
Thread.sleep(2000);
System.out.println(" Device Name is "+results.getField("SmartCartDeviceName"));
System.out.println(" ");
System.out.println("....Device name is sent successfully from the excel sheet.....");
System.out.println(" ");
//Click on Save button after sending values to the respective text boxes
System.out.println("...Click on Save button....");
WebElement save_btn=driver.findElement(By.xpath(rx.readdatafromexcel("sheet1",4,1)));
mod.click(save_btn);
Thread.sleep(2000);
System.out.println(" ");
System.out.println("......Save button is clicked successfully.....");
//Handle Confirmation Pop up
System.out.println(" ");
System.out.println(".....After click on save confimation window will appear....");
System.out.println(" ");
WebDriverWait wait=new WebDriverWait(driver,30);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath(rx.readdatafromexcel("sheet1",5,1))));
System.out.println("....Wait for element to be clickable.....");
WebElement ok_pop=driver.findElement(By.xpath(rx.readdatafromexcel("sheet1", 5,1)));
mod.click(ok_pop);
Thread.sleep(2000);
System.out.println(" ");
System.out.println("....Successfully clicked on confirmation ok.....");
System.out.println(" ");
System.out.println(".....Successfully completed data retrievation from excel sheet.....");
System.out.println(" ");
}
}
}
readfromexcel is my function for reading data from excel. It contain xpath of all webelement.