Reputation: 3
I have an html like this
<td class="select", dataId="12o312p3o"> <span>
<a>something</a> </span> </td>
and lots of same td-s, just dataID is different. I want to select the td by dataID, but cannot find a way to do it. I am using selenium webdriver. Is this possible, and if it is - how could i do it?
Upvotes: 0
Views: 1669
Reputation: 459
If solution provided above are not working you could write some custom websdriver + Java code like:
WebElement e = driver.findElement(By.xpath("//td[@class='select']"));
String s = e.getAttribute("dataId");
if(s.equals("12o312p3o"){
//do something
} else {
//do something different
}
Upvotes: 0
Reputation: 412
To Find Element that has data-id
with value 12o312p3o
:-
By Css Selector-
driver.findElement(By.cssSelector("td[data-id=12o312p3o]"));
By X-Path-
driver.findElement(By.xpath("//td[@data-id='120312p30']"));
To Find Element that has data-id
with value 12o312p3o
and class
as select
:-
By Css Selector-
driver.findElement(By.cssSelector("td.select[data-id=12o312p3o]"));
By X-Path-
driver.findElement(By.xpath("//td[@data-id='120312p30' and @class='select']"));
Upvotes: 1
Reputation: 1105
Sure you can. Use xpath as follows:
WebElement elem = driver.findElement(By.xpath("//td[@data-Id='12o312p3o']"));
Upvotes: 0