The first line should be correct. WebDriver wants the locator for findElement and the attribute for getAttribute. There are some changes to WebDriver however. For example, in Selenium 1.0 you could get an invisible element and interact with it. Because a user would never interact with an invisible element, this was removed from WebDriver.
Maybe you are encountering this. Chaining calls works if you know the call works. If it is throwing an exception you might know if was line X but you will have a harder time determining if it was the driver, the findElement or the getAttribute call. Try writing it as:
WebElement img = driver.findElement(By.xpath("//tr[" + i + "]/td[11]/a/img"));
String src = img.getAttribute("src");
If it dies on the first line, you know it is in the findElement, By.xpath. It is also possible there are two problems and you cannot see that. Breaking it apart into two lines I also noticed that you were using td[10] in Selenium 1.0 but you are using td[11] in WebDriver. According to XPath, these should be 1-indexed. I'm guessing Selenium 1.0 was 0-indexed so you have to change the 10 to an 11. What about the tr? Did you increment i by 1? Or should you just be using:
WebElement img = driver.findElement(By.xpath("//tr[" + (i+1) + "]/td[11]/a/img"));
Darrell
On Friday, 5 October 2012 10:53:29 UTC-4, GiuseppeC wrote:
Hi guys.
I'm converting my selenium-tests from selenium 1.0 to selenium 2.0.
How I can substitute this expression session().getValue("//tr["+i+"]/td[10]/a/img/@src") in webDriver?
I have tried this
driver.findElement(By.xpath("//tr["+i+"]/td[11]/a/img")).getAttribute("src")
or
driver.findElement(By.xpath("//tr["+i+"]/td[11]/a/img")).getCssValue("src")
but both don't work.
Thanks.:)
GC