Daniel Cllini
Daniel Cllini

Reputation: 5

How to get the text attribute of a input element? - webdriver

<ul class="list-group opened-list d-none" xpath="1">
    <li class="list-group-item col-12" xpath="1">My team</li>
    <li class="list-group-item col-12" xpath="1">My name</li>
    <li class="list-group-item col-12" xpath="1">My film</li>
    <li class="list-group-item col-12" xpath="1">My football teammate</li>
  </ul>

Dropdown list without select tag

Upvotes: 0

Views: 56

Answers (1)

Sers
Sers

Reputation: 12255

To get all li elements use .list-group.opened-list .list-group-item css selector.
Code below wait visibility of li elements and then print text for each:

WebDriverWait wait = new WebDriverWait(driver, 10);
List<WebElement> options = wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.cssSelector(".list-group.opened-list .list-group-item")));
options.forEach(element -> System.out.println(element.getText()));

If you want to select one of the element by text, check example here.

Upvotes: 1

Related Questions