I have xpath written in Selenium RC & now I want to write the same xpath in selenium Webdriver. below is the xpath:
"//table[@id='lgnLogin']/tbody/tr/td/table/tbody/tr[4]/td"
by using this xpath, i am capturing the error message displayed on my application like “Please check your Password”.
Now how can I write it in Webdriver. I have different ways but, not worked out.
"String msg= driver.findElement(By.xpath("//*[@td='error2']")).toString();" – This is what i did in Webdriver.
Please help me out on this…
The XPath hadn’t change from Selenium RC to WebDriver.
If you were able to use the some XPath-expression before it should work in WebDriver too (in 99% of cases as usual).
The code below should work but it’s pretty hard to answer without seeing your HTML.
//*[@td='error2']– this expression looks bad as it means “any element with attribute named “td” and value “error2”. I suppose that you don’t have ‘td’ attributes in your HTML.And to the end. I wouldn’t recommend to use such long XPath expressions as in your example. It might be broken due to any minor change in layout. It’s better to use some specific attributes rather than long hierarchy.