How to get attribute value inside a div in webdriver

0
0

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

  • You must to post comments
0
0
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.

  • You must to post comments
Showing 1 result
Your Answer
Post as a guest by filling out the fields below or if you already have an account.
Name*
E-mail*
Website