Subscribe Us

How To Select The Value From Dropdown in Selenium Webdriver

.
Question :How To Select The Value From The Dropdown in Selenium Webdriver ?

Answer :
By using the select class we select the value from the dropdown.

Step-1 First import the select package 
Step-2 Now Create the object of select class.
Step-3 Locate the element by using method available in select Class

List of method available in select class
1) SelectByVisibleText();
2) SelectByindex();
3) SelectByValue

here , In Below Example we use the selectByVisibleText(); method to select the value from the dropdown .

Selenium Code to Select the value from the dropdown .

1) selectByVisibleText() 
Select by visible text is used to select the value form the dropdown. 

Code:
package automation;
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 SelectInSelenium
{
public static void main(String[] args)
{
System.setProperty("webdriver.chrome.driver", "C:\\Software\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.manage().window().maximize();
driver.navigate().to("http://demo.guru99.com/test/newtours/register.php");
Select ddown =new Select ( driver.findElement(By.name("country")));
ddown.selectByVisibleText("ANGOLA");
driver.close();
}
}

In this tutorial we learn how to Select the value from the dropdown in selenium webdriver with various types .Hope this tutorial helpful for you 😊

Thanks & Regards 
Sandeep Yadav

Related Post :

  • How to select the radio button in selenium 
  • How to Deselect the value from the dropdown in selenium Webdriver
  • How to Select the multiple Value From the Drop down in selenium webdriver 
  • How to Click on Link In Selenium webdriver

Important Tags :
 how to select the value from the dropdown in selenium , How to select the value from the dropdown in selenium webdriver using java . Select method in selenium .


How To Select The Value From Dropdown in Selenium Webdriver 




Post a comment

0 Comments