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

  • Home
  • SEARCH
  • 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 8337869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:25:05+00:00 2026-06-09T04:25:05+00:00

I am trying a select a text from the Dropdown Menu using Selenium webdriver

  • 0

I am trying a select a text from the Dropdown Menu using Selenium webdriver in C#
It is working perfectly with Chrome browser, but not with Firefox. Could any one help me to fix this.

The code I am using is given below.

public void SelectCountry1(string country)
{
var countryDropDown = Driver.FindElement(By.XPath(xpathidofthecountrydropdown));
countryDropDown .Click();
//Driver.FindElement(By.XPath(xpathidofthecountrydropdown)).Click;
var selectElement = new SelectElement(countryDropDown);
selectElement.SelectByText(country);
}

I am able to call this function and this is executing successfully without any error messages. I am not able to select the expected keyword eventhough it exists.

Currently I am having a workaround of Clicking on the same id twice and that makes the code to work. With the commented section uncommented But I dont think that is correct workaround. Let me know your thoughts on this.

Thanks

  • 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-09T04:25:08+00:00Added an answer on June 9, 2026 at 4:25 am

    Yah, it doesn’t work well with Firefox. I had to use this as a workaround using jQuery. Feel free to modify this code with regular JavaScript if you don’t have jQuery on the page.

    public static void SetDropdownSelectedOptionByText(IWebDriver driver, string tagId, string newText, int sleepTime)
    {
        // not working when selecting client id of certain types of ASP.NET user controls
        //new SelectElement(driver.FindElement(By.Id(tagId))).SelectByText(newText);  
    
        IJavaScriptExecutor js = driver as IJavaScriptExecutor;
        js.ExecuteScript("$('#" + tagId + " option:contains(" + Element.NonNullValue(newText) + ")').attr('selected', 'selected')");
        js.ExecuteScript("$('#" + tagId + "').change()");
        System.Threading.Thread.Sleep(sleepTime);  // wait for dependent dropdown to load its values
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to remove text from a dropdown menu using a Jquery plugin
I'm trying to get the selected text from a dropdown using a selector. If
I'm trying to select the text from the name attribute of the anchor element
I am trying to select the last record from a table in MySQL using
I'm trying to grab the text from options in a dropdown list. Assume that
I am trying to prevent the user from picking the default dropdown menu option.
I'm having trouble trying to accomplishing this.. Whatever option I select from a dropdown
I am trying to display from a MySQL Database using PHP and Ajax but
I am using following code but in it small caps is not working,please help
I am trying to get the selected Text from the dropdownlist using Jquery. <div>

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.