Java, .NET, PHP, PYTHON, ANGULAR, ML, Data Science, Testing, CI Tutorials in Easy Languages.

"Best Software Training, Internship, Project Development center of Indore India, Helpline 780506-3968"


Combobox or SelectBox or Dropdownlist:-

it is used to select a single item in a group of items.

HTML Code:-

<select name="c" id="c">
<option value="">Select Selenium Component</option>
<option value="Web Driver">Web Driver</option>
<option value="TestNG">TESTNG</option>
<option value="Selenium GRID">Selenium GRID</option>
</select>

WebDriver Code to get data from select box:-

Select ref = new Select(driver.findElement(By.name("c"));
ref.selectByValue()
ref.selectByVisibleText()
ref.selectByIndex()
ref.deSelectByValue()
ref.deSelectByVisibleText()
ref.deSelectByIndex()

....................................................................................................................

ListBox in WebDriver:-

It is used to Select Multiple Item at a time

HTML Code for ListBox

<select name="c[]" id="c" multiple="true">
<option value="">Select Selenium Component</option>
<option value="Web Driver">Web Driver</option>
<option value="TestNG">TESTNG</option>
<option value="Selenium GRID">Selenium GRID</option>
</select>

WebDriver Code to get data from select box:-

Select ref = new Select(driver.findElement(By.name("c1[]"));
ref.selectByValue()
ref.selectByVisibleText()
ref.selectByIndex()
ref.deSelectByValue()
ref.deSelectByVisibleText()
ref.deSelectByIndex()


Complete Code of WebDriver for ListBox and ComboBox:-

package basic;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;

public class ListandComboExample {

public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","c:\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("file:///E:/htmltest/demo1.html");
Select s = new Select(driver.findElement(By.name("c")));
//s.selectByIndex(2);
//s.selectByVisibleText("TESTNG");
s.selectByValue("TestNG");
Select s1 = new Select(driver.findElement(By.name("c1[]")));
//s.selectByIndex(2);
//s.selectByVisibleText("TESTNG");
s1.selectByValue("TestNG");
s1.selectByIndex(3);


}

}



Post a Comment

POST Answer of Questions and ASK to Doubt

Previous Post Next Post