Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用Selenium工具的自动化脚本_Java_Excel_Selenium Webdriver - Fatal编程技术网

Java 使用Selenium工具的自动化脚本

Java 使用Selenium工具的自动化脚本,java,excel,selenium-webdriver,Java,Excel,Selenium Webdriver,我需要有关自动化脚本的帮助 首先,我需要单击添加按钮,这样它将打开设备id和设备名称文本框。我正在使用filo从excel工作表向该文本框传递一个值,然后单击“保存”。我正在从excel表格中读取数据。对于任何现有值,它将从excel工作表中逐个提取数据。但是,如果我在工作表中输入新数据并尝试获取它,将抛出一个错误 元素不可见 这是我的剧本: public void Click_Smart_Cart_Button() throws IOException, FilloException, Int

我需要有关自动化脚本的帮助

首先,我需要单击添加按钮,这样它将打开设备id和设备名称文本框。我正在使用filo从excel工作表向该文本框传递一个值,然后单击“保存”。我正在从excel表格中读取数据。对于任何现有值,它将从excel工作表中逐个提取数据。但是,如果我在工作表中输入新数据并尝试获取它,将抛出一个错误

元素不可见

这是我的剧本:

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是我从excel中读取数据的函数。它包含所有webelement的xpath。

那么,您的“保存按钮”是否在读取数据的同一excel中?如果不是,我看不到您将数据添加到文件的位置?我可以看到您正在按“保存”按钮,但不确定该按钮的位置。我有两张excel表格。一张用于存储我的所有web元素x-path,另一张用于测试数据。我的保存按钮在我的x-path表格中。