Legend Legend - 1 year ago 96
Java Question

Element is found in XPath Checker but not in Selenium

I have the following XPath:

//div[contains(@id, 'box')]/div/h4/small/a[contains(@href, 'google')]/@href

When I try out this XPath in XPath Checker (Firefox extension), it works perfectly all the time. But when I do the following in Selenium:

System.out.println(selenium.getAttribute("//div[contains(@id, 'box')]/div/h4/small/a[contains(@href, 'google')]/@href"));

It keeps giving me the following log error:

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

I am going crazy to solve this problem. Does anyone see any mistake that I have in my code line?

Answer Source

Shouldn't that query string look like this (according to javadoc api)?

"xpath=//div[contains(@id, 'box')]/div/h4/small/a[contains(@href, 'google')]/@href"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download