Saturday 30 July 2022

Selenium Select Dropdown Value | Selenium Select Class | Selenium Webdriver Select Dropdown Java

                    In this post, we will see Selenium Select Dropdown Value | Selenium Select Class | Selenium Webdriver Select Dropdown Java 


Program Code (SelectDropdown.java)

package main;


import java.time.Duration;


import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;

import org.openqa.selenium.support.ui.Select;


public class SelectDropdown {


public static void main(String[] args) {

System.setProperty("webdriver.chrome.driver", "C:\\selenium\\chromedriver_win32\\chromedriver.exe");

WebDriver driver=new ChromeDriver();

driver.get("https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_select");

driver.manage().window().maximize();

driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));

driver.switchTo().frame("iframeResult");

WebElement w=driver.findElement(By.xpath("//select[@id='cars']"));

Select dropdown=new Select(w);

dropdown.selectByIndex(2);


}


}


Watch following video:


Watch on YouTube: https://www.youtube.com/watch?v=xgulzaH7FFc


No comments:

Post a Comment