Having difficulty choosing an option from the dropdown menu using Selenium WebDriver

I am currently using Selenium Webdriver version 2.41 along with Chrome version 68. My goal is to select an item from a dropdown list:

<div id="loc_placeholder" class="jLocPlaceholder" style="">All locations</div>
    <select id="location_facet" name="location_facet" class="search_input font_bold multiselect jLocInput chzn-done" data-placeholder="All locations" multiple="" style="display: none;">
      <option value="233">United Kingdom</option>
      <option value="250">Netherlands</option>
      <option value="228">United States</option>

However, despite my efforts and numerous attempts with various options, I have not been successful in making the code below work. The driver simply cannot select any option :/

 WebElement location = driver.findElement(By.id("loc_placeholder"));
 location.click();

 Select dropdown = new Select(driver.findElement(By.id("location_facet")));
 dropdown.selectByValue("250");
 //dropdown.selectByIndex(1);     
 //dropdown.selectByVisibleText("Netherlands"); 

When I click on the dropdown, the list expands.

The dependencies for this project are as follows:

 <dependencies>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-server</artifactId>
            <version>3.11.0</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-chrome-driver</artifactId>
            <version>3.13.0</version>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

An error I encountered was:

org.openqa.selenium.ElementNotVisibleException: element not visible: Element is not currently visible and may not be manipulated

(Session info: chrome=68.0.3440.75) (Driver info: chromedriver=2.41.578737 (49da6702b16031c40d63e5618de03a32ff6c197e),platform=Windows NT 10.0.17134 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 0 milliseconds Build info: version: '3.11.0', revision: 'e59cfb3', time: '2018-03-11T20:26:55.152Z'

Answer №1

Thank you for your assistance! :) I changed the style="display: none; to block and now it is showing up.

((JavascriptExecutor)driver).executeScript("jQuery('#location_facet').css('display','block')");
        Select select = new Select(driver.findElement(By.id("location_facet")));
        select.selectByVisibleText("Netherlands");

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Searching for elements using Select Element

Struggling to execute this piece of code due to a null pointer error on the Select element... Check out the snippet of my code below: @FindBy(id="ddCompany") WebElement Select; public void Test(){ driver.findElement(By.id("igtxtdfUsername") ...

Tips for resolving error "Exception in main thread java.lang.NoClassDefFoundError: com/fasterxml/jackson/annotation/JsonView":

I am attempting to assess a json string by utilizing the jackson library's ObjectMapper. I have included the jackson-annotation, jackson-databind, and jackson-core dependencies with the matching version in the pom.xml file. However, the code is produc ...

Accessing input fields within an HTML form using Selenium.Note: Please provide

I am struggling to select input fields from this specific form in Selenium. Despite trying multiple methods, my test consistently fails. Here is the HTML form in question: `<form class="login" action="/Index/trylogin/?ru=L015RmlueWE=" novalidate> ...

Guide to generating a map of a Java POJO class or JSON String with basic data types

I need to create a Map (String, Object) with the following format: {AssessmentId=0, Physical_name='ram', Physical_height=20, Physical_weight=60} This map will be constructed from my Pojo Class - InitialAssessment public class InitialAssessment ...

Swipe down to view all the links

Out of 3821 links, only 103 were provided to me. I tried applying the condition `window.scroll` to retrieve all the links, but unfortunately, it did not work as expected. from selenium.webdriver.common.by import By from selenium.webdriver.common. ...

Is there a way to retrieve the xpath on a website, such as IRCTC, if the right-click function is disabled? Furthermore, how can webdriver be used to handle

Recently, I've written a code snippet to launch the IRCTC website using Selenium WebDriver. Now, I'm wondering how can I locate elements by xpath for the login process? Also, is it feasible to automate the captcha verification? public void initi ...

Interference with Element Click in Python Selenium

Having trouble with clicking a cookie button in my code. Despite using explicit wait 'element_to_be_clickable', I'm receiving an error message. Any insights on why this element can't be clicked? PATH = 'C:\Program Files (x86)& ...

Searching for a hyperlink WebElement with Java and Selenium: Finding the way to locate it

I have been attempting to click on the "sign out" link in Gmail, but my console keeps stating that it cannot find the element. Here is the code I'm using. Thank you! @FindBy(linkText="Sign out") WebElement logoutLink; This is the HTML: view image de ...

Entering a date in a disabled datepicker using Selenium

I am encountering an issue while trying to input my own chosen date as the datepicker is disabled. Whenever I click on the datepicker, it prompts me to select a specific date and even for changing the month, multiple clicks are required. This has left me f ...

Effortless File Uploading in JERSEY using jquery and AJAX

I'm looking to achieve file uploads with Jersey through jQuery/AJAX, but I'm struggling with extracting the file from the input and sending it via AJAX. Below is my current code: HTML <form action="rest/files/upload" method="post" enctype=" ...

Executing Python Selenium Tests in Headless Mode

I'm facing some challenges when trying to run Webdriver on a specific hub in headless mode using Pyvirtualdisplay. The generic code below works without any issues: class TestHub4444TestClass01(unittest.TestCase): def setUp(self): self.di ...

Trouble with clicking the button in Selenium Webdriver? Element located but unable to be clicked

Can anyone assist me in finding a solution to my current problem? I have dedicated a significant portion of today trying various solutions both on this platform and through Google. To get straight to the point, I am facing an issue with Selenium automatio ...

Retrieving an item using a known path even without the id information

I am currently developing a testing program that functions under limited information. In this specific scenario, my program lacks prior knowledge of the element IDs on the page as they are assigned dynamically by Javascript at runtime. The only constants ...

Is there a way to modify System.out.println to only retrieve links that have child p tags in Java

How do I make System.out.println show only links with /p/ in them? I am working on a program to display all links by hashtag on Instagram. I have managed to parse all links with the "a" tag. How can I now filter out links that do not contain /P/? ...

Tips for Verifying Success and Error Messages from a Login Form with Selenium Automation Testing

The code snippet provided below demonstrates how to perform a G-mail login using Selenium WebDriver. package gmail_Login; import java.util.concurrent.TimeUnit; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.openqa.selen ...

Using Spring Boot to create a multiple select feature with Materialize CSS

Currently engaged in a Spring Boot project utilizing Materialize CSS for the frontend. Everything runs smoothly when running the HTML file independently, with the Materialize CSS multiple select feature working perfectly. However, upon integrating the HTML ...

Encountered an issue when parsing JSON in Spring Boot: Unable to deserialize the

I'm encountering issues when trying to submit the form. Despite making changes in RoominfoController to accommodate arrays, the problem persists. Cannot deserialize value of type `com.example.pgfinder.models.RoomInfo` from Array value (token `JsonToke ...

Encountering an issue with GSON while attempting to convert an array of objects with

I'm trying to make a HTTP request using Retrofit that should return an array of objects, but unfortunately I'm encountering the following errors: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was ...

Getting a string array from a JSON object within the deserialize method

I am working with a JSON object that looks like this: { "name": "John", "age": 29, "bestFriends": [ "Stan", "Nick", "Alex" ] } In my code, I have created a custom implementation of JsonDeserializer: public class CustomDeserializer im ...

Checking for URL redirection in Selenium automation can be done with the following steps

Attempting to automate the verification of top navigation links on . https://i.stack.imgur.com/Mt6Zw.png When comparing actual URLs with expected URLs in the page class method, the line below returns null. I'm not sure why. String urlp = locator.all ...