Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get attribute value inside a div in webdriver

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

like image 362
user2572510 Avatar asked Jul 11 '13 11:07

user2572510


1 Answers

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.

like image 113
Arran Avatar answered Oct 21 '22 07:10

Arran