views:

1029

answers:

2

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?

+1  A: 

According to the API doc, it should be

...getAttribute("xpath=//div[contains....
Jim Garrison
Perfect! Thanks a lot... I guess I'm on too much of caffeine!
Legend
+2  A: 

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"
jitter
Thank You... That fixes it...
Legend
Selenium should know that this is an xpath locator because it starts with `//`. I would have suspected the `/` before the final `@href`
Dave Hunt
Default locators in Selenium http://seleniumhq.org/docs/04_selenese_commands.html#default-locators
Dave Hunt