In the following HTML i need to get the login value using Selenium Webdriver.
<div
roletitle="MD"
careteamrole="HOSPITALIST"
login="adamss"
isconsultctm=""
title="Adams Samuel"
style=""
class="assign_grid assign_grid_selected"
id="97">
</div>
I tried the following, but it failed:-
WebElement getAssigneeLoginWebElement = ieDriver.findElement(By.cssSelector(".assign_grid assign_grid_selected"));
sAssignedCTMLoginId = getAssigneeLoginWebElement.getAttribute("login");
sAssignedCTMLoginId = ieDriver.findElement(By.className("assign_grid assign_grid_selected")).getAttribute("login");
sAssignedCTMLoginId = ieDriver.findElement(By.xpath("//*[@class='assign_grid assign_grid_selected']/@login[1]")).getText();
Thank you in advance
ieDriver.findElement(By.xpath("//div[@class='assign_grid assign_grid_selected']")).getAttribute("login");
I'd also check to ensure that the locators you are using are only bringing back that one element, and not more - to check this, run the same thing using .findElements
and verify only one single result is returned.
It is common that there are hidden elements in the HTML, and your locator may be picking them up.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With