Selenium WebDriver查找第n个元素 [英] Selenium WebDriver Find nth element
本文介绍了Selenium WebDriver查找第n个元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有点陷入问题,无法解决它,我必须访问HTML内表格中的页面上的第n个图像.我需要单击图像分别移至每一行的下一个屏幕
I am kinda stuck in a problem and am not able to fix it I have to access nth image on my page which comes in table inside HTML. I need to click on image to move to next screen respectively for each row
我尝试了此处提供的各种解决方案,但是由于我正在使用findElement(by)语法,因此无法在这些帮助下运行代码
I have tried various solution provided here but since I am working with findElement(by) syntax I am not able to run my code with those assistances
我的代码是:
public void editUser(String userName)
{
System.out.println("in editUser 1");
int row = getCellRow(table, userName);
System.out.println("in editUser 2");
WebElement edit = driver.findElement(By.xpath("//*[@class='grid']/tbody/tr[2]/td[8]/a[1]/img"));
System.out.println("in editUser 3");
edit.click();
System.out.println("in editUser 4");
clickButton(closeButton);
}
错误是:
No such element exception. Unable to locate element: {"method":"xpath", selector"://img[@title='User Management'])[2]
Selenium IDE可以识别我的元素,但不能识别Selenium Web驱动程序! 请指教
Selenium IDE could recognize my element but not selenium web driver ! Please advice
推荐答案
使用[]引用实例的第n个元素
Use [ ] to reference the nth element for instance
WebElement edit = driver.findElement(By.xpath("(//*[@class='grid']//img)[n]"));
其中n是元素编号
这篇关于Selenium WebDriver查找第n个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文