How to select an item in the ListBox in Selenium Webdriver unordered (bulleted) list!!!!

7:05 AM 0 Comments

Handling the Listbox in Selenium WebDriver in the below website http://www.cheapflights.com/ is shown below:







HTML <ul> Tag
The <ul> tag defines an unordered (bulleted) list.
Use the <ul> tag together with the <li> tag to create unordered lists.
References->http://www.w3schools.com/tags/tag_ul.asp
HTML Code for ListBox in http://www.cheapflights.com/: 
<ul class="ui-dropdown-list">
<li class="ui-dropdown-selected notranslate" data-value="">1</li>
<li class="notranslate" data-value="">2</li>
<li class="notranslate" data-value="">3</li>
<li class="notranslate" data-value="">4</li>
<li class="notranslate" data-value="">5</li>
<li class="notranslate" data-value="">6</li>
<li class="notranslate" data-value="">7</li>
<li class="notranslate" data-value="">8</li>
<li class="notranslate" data-value="">9</li>
</ul>
Selenium WebDriver Code For Selecting a Value from the ListBox:

import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;


public class HandlingListbox {
 
 public static void main(String[] args) {
 WebDriver driver = new FirefoxDriver();
 driver.get("http://www.cheapflights.com/");
 driver.findElement(By.cssSelector("#sb-adults>div>.arrow")).click();
 List<WebElement> liList = driver.findElements(By.cssSelector(".ui-dropdown-list>li.notranslate"));
 liList.get(3).click(); 
 }

}

Output:

Unknown

This site creates a platform to become an expert by gaining knowledge of unknown real-time issues as well.

0 comments: