内部html中的对象未被selenium web驱动程序识别

时间:2016-12-14 08:24:12

标签: java selenium xpath selenium-webdriver

我想选择并点击内部html中的对象(如图所示)。但目标尚未确定。我正在使用Java。

注意 - >我的应用程序没有打开任何浏览器,除了Internet Explorer,我无法从控制台/调试器验证xpath,所以我必须通过代码验证它。

我到目前为止尝试过的代码但是没有为我工作 - >

选项1 - >

driver.switchTo().frame("nav");
driver.findElement(By.xpath("//a href[@text='Administrate']")).click();

选项2 - >

driver.switchTo().frame("nav");
driver.findElement(By.xpath("//a[@text='Administrate']")).click();

选项3 - >

driver.findElement(By.xpath("/html/frameset/frame[1]/html/body/ul/li/ul/li[1]")).click();

I have pasted the html structure here

2 个答案:

答案 0 :(得分:1)

您正在检查确切的文字匹配,请改用<{1}}

contains

或者

driver.findElement(By.xpath("//a[contains(text(), 'Administrate')]")).click();

请注意driver.findElement(By.xpath("//a[contains(., 'Administrate')]")).click(); text()

之间的区别

答案 1 :(得分:0)

您需要像

一样更改XPath
driver.switchTo().frame("nav");
driver.findElement(By.xpath("//a[text()='Administrate system']")).click();

注意: - 在这里你需要传递完整的字符串以便更好地学习,请参考 Firepath来创建和评估你的xpath

也可以使用contains方法在部分文本基础上查找元素

相关问题