RVK
RVK

Reputation: 29

Unable to find an element using webdriver

I'm trying to locate a tab which is a png image. I have the source of the tab. But I have tried the follwoing options:

1)

WebElement image = driver.findElement(By.id("x", "a"));
String src = image.getAttribute("src"); 
src.contains("x.png");

2)

WebElement image = driver.findElement(By.name("x"));

I'm unable to do find it.its not a hidden element as well...any inputs???? would be much appreciated...

Upvotes: 1

Views: 3117

Answers (1)

Anuragh27crony
Anuragh27crony

Reputation: 2957

Please try this way...

When i have image tags of this type and think id "Size50" is unique

<img id="Size50" src="http://sp2010-sa/talk/harold/Photos/_t/Profile_jpg.jpg"/>

Selenium will search in this way...

WebElement image=Driver.findElement(By.TagName("img")).findElement(By.id("Size50"));

The above code, first searches for all Image Tags and later within Image tags it will search for a Tag with unique ID "Size50".

if the Id "Size50" is unique on the page then we can directly write the following

WebElement image=Driver.findElement(By.id("Size50"));

Upvotes: 1

Related Questions