Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8594673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:15:09+00:00 2026-06-12T00:15:09+00:00

How do we find the selected option of a Dropdown in Selenium Webdriver?? I

  • 0

How do we find the selected option of a Dropdown in Selenium Webdriver??

I tried –

WebElement element = driver.findElement(By.xpath(locator1));
Select select = new Select(element);
List<WebElement> SO = select.getAllSelectedOptions();
String S = SO.toString();
System.out.println(S);

which returns WebElements like –

[[[[[FirefoxDriver: firefox on XP (c388e8a8-09d5-41b9-b086-0278c639d8b1)] -> xpath: .//*[@id='city']]] -> tag name: option]]

I want to find the option that is selected?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T00:15:10+00:00Added an answer on June 12, 2026 at 12:15 am

    You can use the getFirstSelectedOption() method on your Select object to resolve the selected element and you can get it’s text by the getText()method. See example below:

    For single selection:

    WebElement element = driver.findElement(By.xpath(locator1));
    Select select = new Select(element);
    WebElement selectedOption = select.getFirstSelectedOption();
    System.out.println(selectedOption.getText());
    

    For multiple selection:

    WebElement element = driver.findElement(By.xpath(locator1));
    Select select = new Select(element);
    List<WebElement> selectedOptions = select.getAllSelectedOptions();
    for(WebElement selectedOption : selectedOptions) {
        System.out.println(selectedOption.getText());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this drop down code: $('#addDropdown').click(function() { var $d = $('<select class=dropdown><option selected=selected
I need a jquery selector that allows me to find input (select/option) dropdown -
With my current node selected I wish to find an element <name> [./name] and
<table> <tr> <td> <select class=dropdown id=a> <option value=>Select answer</option> <option value=1 >Yes</option> <option value=2>No</option>
Here is my HTML Code. <table> <tr> <td> <select class=dropdown> <option value=>Select answer</option> <option
Say I have this dropdown: <select id=theOptions1> <option value=1>1</option> <option value=2>2</option> <option value=3>3</option> </select>
Is it possible to find and replace in selected text in Snow Leopard Xcode
I have a website I need to find the id of my selected profile
I'm trying to find a way of displaying the text of the selected/initial value
I have a dropdown which you choose one of three values <select id=FilterType name=FilterType>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.