What's wrong in my Xpath? Please help.

117 views
Skip to first unread message

Ashvini Sharma

unread,
Feb 18, 2015, 10:10:10 AM2/18/15
to webd...@googlegroups.com
Hi,

I am newbie in selenium. (Using Webdriver + Java).

I am working with sample for iframe. I want to locate a iframe on web page. 
I used Google chrome's inspect element section to find xpath. Also, I have verified xpath from "Xpath Finder" and it shows correct.

This is my xpath: //*[@id="content"]/tbody/tr/td/p[9]/iframe

However, whenever I am using this Xpath in my code:

//String locator = "//*[@id="content"]/tbody/tr/td/p[9]/iframe"
//WebElement frame = driver.findElement(By.xpath(locator));
//driver.switchTo().frame(frame);


I am getting following exception:
Unknown error: Runtime.evaluate threw exception: DOMException: Failed to execute 'evaluate' on 'Document': The string '(/html/body//iframe|/html/frameset/frame)[@name="//*[@id="content"]/tbody/tr/td/p[9]/iframe" or @id="//*[@id="content"]/tbody/tr/td/p[9]/iframe"]' is not a valid XPath expression.


Please suggest. Appreciate your help. 

Thanks,
Ashvini

Rohit Patwari

unread,
Feb 19, 2015, 12:34:12 AM2/19/15
to webd...@googlegroups.com

Enclose content in single quote ..'content'

--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webdriver+...@googlegroups.com.
To post to this group, send email to webd...@googlegroups.com.
Visit this group at http://groups.google.com/group/webdriver.
For more options, visit https://groups.google.com/d/optout.

Ashvini Sharma

unread,
Feb 28, 2015, 11:01:39 AM2/28/15
to webd...@googlegroups.com
Thank Rohit.
I just figured out that I was using relative path, I took absolute path and it worked. 
However, I am not sure that is this limitation of selenium that only absolute path will work.

Ram krishna

unread,
Mar 3, 2015, 5:43:43 AM3/3/15
to webd...@googlegroups.com
Hi Shravani,

There is nothing like that... Selenium Supports the relative Path, It depends on the way we have written/constructed the xpath.

Regards
Ramakrishna
Reply all
Reply to author
Forward
0 new messages