Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 97785

How to extract the text of the firstselectedoption from a dropdown using Selenium Webdriver through Java

$
0
0

After selecting an option from drop-down. I am trying to get that option displayed in the console. below is my code. But I get

"//[[[[ChromeDriver: chrome on WINDOWS (d5a01776981da5dacfeb89dbbc2e6b52)] -> xpath: //*[@name='airline']]].// -> tag name: option]"

The tag name is option for dropdown options. I have tried all solutions of selectByXXXX. but nothing seems to work. what would be the right code ?

//airline preference
{
    Select airline = new Select (driver.find Element(By.name("airline"))); //selecting tag
    Thread.sleep(2000); //sleeptime`
    airline.selectByVisibleText("Pangea Air"); //selecting option
    Thread.sleep(2000); //sleep time
    Select airlin = new Select (driver.findElement(By.xpath("//*[@name='airline']"))); //omg
    WebElement s = airlin.getFirstSelectedOption();
    Thread.sleep(2000);
    System.out.println(s);
}

Viewing all articles
Browse latest Browse all 97785

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>