How To Select the Value From dropdown in selenium Webdriver Using Java

How to Select Value from Drop Down in Selenium Webdriver


In This Chapter We are Going to Learn  how to handle Drop Down and Multiple Select Operations
In selenium there are 3 method to select the value from the dropdown 
1)selectByVisibleText();
2)selectByValue();
3)selectByIndex();

Before we can control drop-down boxes We have to do 2 things-
Step-1 Import the package org.openqa.selenium.support.ui.Select
Step-2 Instantiate the drop-down box as a "Select" object in WebDriver

Selenium Code for select the value from the drop down using java

1)selectByVisibleText();

package automationtesting;
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 HandlingDropDn 
{
 public static void main(String[] argsthrows InterruptedException 
{
              // TODO Auto-generated method stub
              System.setProperty("webdriver.chrome.driver","D:\\Sandeep\\Soft\\chromedriver.exe");
              WebDriver drivernew ChromeDriver();
              driver.manage().window().maximize();
              driver.get("https://www.webfx.com/blog/web-design/50-examples-of-drop-down-navigation-menus-in-web-designs/");
              Select drpdn = new Select(driver.findElement(By.xpath("//*[@id=\"blog-cat-dropdown\"]")));
           drpdn.selectByVisibleText("INTERNET");
              driver.quit();
               

        }
       }



2)selectByValue();

package automationtesting;
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 HandlingDropDn 
{

       public static void main(String[] argsthrows InterruptedException
 {
              // TODO Auto-generated method stub
              System.setProperty("webdriver.chrome.driver","D:\\Sandeep\\Soft\\chromedriver.exe");
              WebDriver drivernew ChromeDriver();
              driver.manage().window().maximize();
              driver.get("https://www.webfx.com/blog/web-design/50-examples-of-drop-down-navigation-menus-in-web-designs/");
              Select drpdn1 = new Select(driver.findElement(By.xpath("//*[@id=\"blog-cat-dropdown\"]")));
    
           drpdn1.selectByValue("/blog/social-media/");
              driver.quit();
}
}


Selecting the value from dropdown in Selenium Webdriver


Hope !! The above code how to Select the value from the dropdown helpful for you ...
Team
QA acharya

Tags: Select the option from the dropdown in selenium , How to select the value from the dropdown , how to select the value from the dropdown list in selenium 

Post a Comment

0 Comments