I have the below code that I am attempting to extract a specific attribute from(data-id). I am new to using selenium and have been pained by this for over a day now.
To add context to this I will give you a little background into what I am trying to achieve.
I have a webpage that has a auction, the auction has an ID, all items in the auction have unique ID's but all link to the original Auction ID. I am attempting to extract the "data-id" attribute of an element however I have yet to find out how. Here is a snippet of the code I am attempting to get the id from.
<div class="dropdown open">
<a class="dropdown-toggle form-control" href="#" data-toggle="dropdown">
<ul class="dropdown-menu dropdown-menu-form" role="menu">
<li id="liAuction4c42556772376a443736343d">
<label class="checkbox">
<input id="chkAuction4c42556772376a443736343d" class="auction" type="checkbox" data-caption="09-10-2015 10:30:00" data-id="4c42556772376a443736343d" checked="checked"/>
09-10-2015 10:30:00
</label>
</li>
</ul>
</div>
I have been on many forums and searched the whole of google and not found a solution that has worked for me yet otherwise I would not be posting the question and look like a complete Rookie.
I have attempted to use .getAttribute however I have had some issues with that and the code has never compiled, I guess I have not done something correctly.
String dataID = selenium.findElement(By.xpath("//*[starts-with(@id, 'liAuction')]")).getAttribute("data-id");
When I attempted the above the "findElement" part is underlined red and I have the following message,
"The method findElement(By) is undefined for the type Selenium".
If I change the parentisis around to look like this;
String dataID = selenium.findElement(By.xpath("//*[starts-with(@id, 'liAuction')]").getAttribute("data-id"));
"findElement" is no longer underlined, however now the ".getAttribute" part is underlined red and I have the following message, "The method getAttribute(String) is undefined for the type By"
I would really appreciate some assistance with this as I am about to throw my laptop out of the window, and I don't really want to lose all of my files.
Thanks in advance
Tony