Reputation: 1111
I am trying to retrieve the value in the data-appid field, I have tried using following-sibling but its not really a sibling per se. Not sure how to go about retrieving this. Any pointers will really be great.
<div class="section app" data-appid="532054761" data-updateid="10184169">
Upvotes: 0
Views: 1085
Reputation: 454
You need to use getAttribute()
method
Try the following code
String dataAppId = driver.findElement(By.xpath("//div[@class='section app']")).getAttribute("data-appid");
System.out.println(dataAppId);
Upvotes: 1
Reputation: 111686
The sibling axis applies to elements, not attributes.
You can reference data-appid
simply as an attribute of the div
element. For example,
//div/@data-appid
will select 532054761
If you need to be more specific about the particular div
element for which you want its data-appid
, you can use a predicate to select a particular div
element. For example:
//div[@data-updateid='10184169']/@data-appid
Upvotes: 2