我有以下 XPath:
//div[contains(@id, 'box')]/div/h4/small/a[contains(@href, 'google')]/@href
当我在 XPath Checker(Firefox 扩展)中试用这个 XPath 时,它一直运行良好。但是当我在 Selenium 中执行以下操作时:
System.out.println(selenium.getAttribute("//div[contains(@id, 'box')]/div/h4/small/a[contains(@href, 'google')]/@href"));
它一直给我以下日志错误:
14:30:56.311 INFO - Got result: OK on session 5a1401d374a04779bbe6f7fe9a0b4536
14:30:56.315 INFO - Command request: getAttribute[//div[contains(@id, 'box')]/div/h4/small/a[contains(@href, 'google')]/@href, ] on session 5a1401d374a04779bbe6f7fe9a0b4536
14:30:56.372 INFO - Got result: ERROR: Element //div[contains(@id, 'box')]/div/h4/small/a[contains(@href, 'google')]/ not found on session 5a1401d374a04779bbe6f7fe9a0b4536
我要疯了才能解决这个问题。有人看到我的代码行中有任何错误吗?
最佳答案
查询字符串不应该像这样(根据 javadoc api)吗?
"xpath=//div[contains(@id, 'box')]/div/h4/small/a[contains(@href, 'google')]/@href"
关于java - 元素在 XPath Checker 中找到,但在 Selenium 中找不到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1711013/