Re: how substitute getValue in webDriver?

176 views
Skip to first unread message

darrell

unread,
Oct 7, 2012, 1:05:03 PM10/7/12
to webd...@googlegroups.com
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

GiuseppeC

unread,
Oct 8, 2012, 5:12:21 AM10/8/12
to webd...@googlegroups.com

Giuseppe Cilia

unread,
Oct 8, 2012, 11:18:55 AM10/8/12
to webd...@googlegroups.com
Ok now works, but why in src expressions takes also baseUrl?

tks

darrell

unread,
Oct 8, 2012, 2:10:07 PM10/8/12
to webd...@googlegroups.com
If it is important to you, you can check out the source code using an SVN client. I would suspect that the WebDriver javascript which retrieves the src attribute is dependent on the browser's javascript engine. If the javascript engine returns the full URL, including the baseUrl, then WebDriver is at the mercy of the javascript engine.

There is occasionally ways to get the relative link but if it is browser dependent you might find the 'trick' only works on some browsers. WebDriver has to pick a method which works for all browsers. This is so the test is consistent across browser.

The only way you will have the real answer to your question is to look at the source code for Selenium 2.0.
Reply all
Reply to author
Forward
0 new messages