How to check selected value in dropdown list using selenium webdriver

Script To check selected value in dropdown list using selenium webdriver

package selenium_examples;



import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;




public class spicejet {

public static void main(String[] args) {


 

WebDriver driver = new FirefoxDriver();
driver.get("http://newtours.demoaut.com");
driver.findElement(By.name("userName")).sendKeys("mercury");
driver.findElement(By.name("password")).sendKeys("mercury");
driver.findElement(By.name("login")).click();
driver.manage().timeouts().implicitlyWait(100,TimeUnit.SECONDS);
    Select droplist = new Select(driver.findElement(By.name("fromPort")));

        droplist.selectByIndex(3);
        System.out.println(droplist.getFirstSelectedOption().getText());
        System.out.println("Done!");
      }
  }

Output:-

New York
Done!

Selenium webdriver script to check selected value in dropdown list


No comments:

Related Posts Plugin for WordPress, Blogger...

Fun and Knowledge