I am testing a website that has an “account” page that displays a table of available subscription levels, where the column headings are the different kinds of accounts, and the rows list all features, and which are available at what level. E.g.:
fanboy poweruser neophyte freeloader
Widgets 1,000 500 250 100
Doodads 750 350 100 100
Thingies 500 250 100 50
[UPGRADE] [UPGRADE] [UPGRADE] Your Plan
This is all done as nested div elements with unique classnames, so finding specific cells by their corresponding classnames is a snap. E.g.:
var yourPlan = driver.FindElement(By.ClassName("your_plan"));
I can also find specific cells by their XPath, if I already know it. E.g.:
var yourPlan = driver.FindElement(By.XPath(".//div[@class='your_plan']"));
But there are times when I need to discover the xpath of the cell I've come to by way of classname, and there doesn't seem to be an easy way to do this in Webdriver (C#). Has anyone done this before?
EDIT: Apologies to all, for not being clearer about this: I'm not having any trouble finding an element by classname or other attribute (or even xpath, when I know it already). But what I need, is a way for webdriver to report the full xpath of what it found to me, once it's found said element via a means other than xpath.
Hope that helps.
Any help appreciated.
Thanks
Greg
There’s not really any way for Selenium to give you this information. While there are some tools that will generate the XPath for a given element (the Firebug and XPather plug-ins for Firefox come to mind), this is not a feature that Selenium provides. I wish I had a better answer for you, but the answer is no, Selenium won’t provide you with the XPath to an element that you’ve found via some other means.