Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

Volkan Ozdamar
Volkan Ozdamar
3,012 Points

Can't Select li element with Selenium

How can i select "Fiyata göre Artan" ?

<div class="search-top hidden-xs"> <div class="destination-info hidden-xs"> <div class="search-sort dropdown open"><div class="pseudo-border-bottom hidden-xs"> </div><div id="result-sort-box" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> <ul id="sort-list" class="dropdown-menu dropdown-menu-sort sort-list" aria-labelledby="result-sort-box"> <li data-sort-theme="plh">Fiyata göre artan</li> <li data-sort-theme="phl">Fiyata göre azalan</li> <li class="active" data-sort-theme="ms">İlgiye göre</li> </ul> </div> </div>

Zoran Zivanovic
Zoran Zivanovic
1,150 Points
//Parameter is a text like is Fiyata göre Artan
public void clickOnElement(String nameOfElement){
WebElement sortList = driver.findElement(By.id("sort-list")); 
List<WebElement> options = sortList.findElements(By.tagName("li"));

for (WebElement option : options) {

if(nameOfElement.equals(option.getText().trim()))

 option.click();   
}
}