Legend Legend - 3 months ago 18
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?


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"