Java, .NET, PHP, PYTHON, ANGULAR, .NET, ML, Data Scince, 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

If you have any doubt in programming or join online classes then you can contact us by comment .

Previous Post Next Post