Lambda expression in Selenium

How to use JAVA Lambda expression to select the value from drop down in selenium.

Let say you have a list and want to select a value from it.

<ul class = 'list'> 
 <li data-value="value1" class="option selection focus">Value1</li>
 <li data-value="value2" class="option selection focus">Value2</li> 
  <li data-value="value3" class="option selection focus">Value3</li> 
 <li data-value="value4" class="option selection focus">Value4</li> 

Below code can select the value from drop down as per the parameter passed in the method  

Public void selectValueFromDropDown(String SearchValue)
WebElement element = Driver.driver.findElements(By.xpath("//ul[@class='list']//li")).stream().
 filter(e-> e.getText().equalsIgnoreCase(SearchValue)).findFirst().get();
         element.click();

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s