Selenium WebdriveR语言 如何单击网格表中的更新图标



这是使用Selenium webdriver(Java)

从GRID视图中单击特定记录的'Update Icon'的代码

我编写了以下代码以单击"更新图标" :-(此代码正常工作)

     //This will count total no of rows in the grid:-
  List<WebElement> count=driver.findElements(By.xpath(".//*[@id='ctl00_ContentPlaceHolder1_gvCustomerDetails']/tbody/tr"));
  int totalNoRecords=count.size();
  System.out.println("total no of rows are  "+totalNoRecords);

  //This will find a particular record in a webtable like po name as selenium_testing11selenium_testing12
  WebElement record=driver.findElement(By.xpath(".//*[@id='ctl00_ContentPlaceHolder1_gvCustomerDetails']/tbody/tr/following::td[text()='selenium_testing11']"));
  String poName= record.getText();
  //This will verify that if po name is equals to this then only click on Update icon else print the else message
  if(poName.equals("selenium_testing11")){
  WebElement updateBtn=driver.findElement(By.xpath(".//*[@id='ctl00_ContentPlaceHolder1_gvCustomerDetails']/tbody/tr/following::td[text()='selenium_testing11']/preceding-sibling::td//a[contains  (@id,'btnUpdate')]"));
  updateBtn.click();
  }
  else
      System.out.println("Po does not exists");
String xpath = "//table[contains(@id, 'gvCustomerDetails')]" + 
"//tr[@class][td[5][text()='%s']]/td[2]/a";
public void clickEditIcon(String po) {
    driver.findElement(By.xpath(String.format(xpath, po))).click();
} 

xpath解释:

//table[contains(@id, 'gvCustomerDetails')]可以定位表
//tr[@class]表示仅找到不是标头列行
的行 [td[5][text()='%s']]是TR上的预选赛,说只能找到第五个 单元格的文本等于参数:po, td[5]表示列:po
/td[2]意味着从匹配的行
中找到第2个单元格(内部更新图标) /a意味着在匹配的单元格中查找更新图标链接

最新更新