【发布时间】:2017-09-12 07:16:47
【问题描述】:
这是使用 selenium webdriver (JAVA) 从网格视图中单击特定记录的“更新图标”的代码
我编写了以下代码来单击“更新图标”:-(此代码运行良好)
//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");
【问题讨论】:
-
您遇到什么错误?请分享
-
您可以尝试使用 xpath 找到特定的行更新按钮元素并单击它。
-
我想点击特定采购订单“selenium_testing11”的更新图标。当我使用该更新图标的 id 时,我可以点击它,但我需要它应该点击我正在传递的 PO 名称的更新图标。我不知道该怎么做。
-
如果我的回答有效,或者您对我的代码有疑问,请说几句话。
-
欢迎来到 Stack Overflow!请参阅:How do I do X? SO 的期望是,提出问题的用户不仅会进行研究以回答他们自己的问题,还会分享该研究、代码尝试和结果。这表明您已经花时间尝试帮助自己,它使我们免于重复明显的答案,最重要的是它可以帮助您获得更具体和相关的答案!另见:How to Ask