Selenium WebElement.getText() on bootstrap dropdown items not working

  • 1 Replies
  • 1031 Views
I'm trying to get the text for each list item in bootstrap buttonDropdown.

When I invoke getText() on the dropdown element's list items the string I get is empty, even though I know I have the right anchor tag elements, since when I run JavaScriptExecutor the correct strings are returned.

Code
List<WebElement> dropdownItemsAnchors = buttonDropdownContainer.findElements(By.xpath("./ul//li//a"));

Code
System.out.println(dropdownItemsAnchors.get(0).getText());
prints empty string.

Code
JavascriptExecutor jsDriver = (JavascriptExecutor)getDriver();
String item = (String)jsDriver.executeScript("return arguments[0].innerHTML", dropdownItemsAnchors.get(0));
System.out.println(item);
prints correct string however.

*

Oren

  • **
  • 59
Re: Selenium WebElement.getText() on bootstrap dropdown items not working
« Reply #1 on: March 09, 2016, 11:20:35 am »
Try clicking on the button dropdown first, then search for child elements.

should work.

They probably don't exist for selenium before you click on their parent

 

Sitemap 1 2 3 4 5 6 7 8