Issue with Selenium Webdriver: Difficulty in selecting a value from dropdown even though the value is present

Currently I am conducting web site testing using Selenium. While working with the dropdowns on the site, I have encountered an issue with one particular dropdown. Manual clicking on the dropdown reveals multiple options, however, when I try to access the elements programmatically and check the size of the Select item, it shows only 1 element. Additionally, selecting by index is not functioning as expected. Based on this, I suspect that selecting by any other option will also not work due to the Select size displaying only one element. The website I am testing can be found at https://test.dormbox.co/, which is part of the second step of my testing process.

 Select pickupTime =
        new Select(
            driver.findElement(
                By.xpath("//*[@id=\"v-register-step2\"]/div/div/div[4]/div/span/span/div/select")));
    WebElement pickup =
        driver.findElement(
            By.xpath("//*[@id=\"v-register-step2\"]/div/div/div[4]/div/span/span/div/select"));
    pickup.click();
    System.out.println("Time Size : " + pickupTime.getAllSelectedOptions().size());
    try {
      pickupTime.selectByIndex(2);
      System.out.println("pickupTime : " + pickupTime.getAllSelectedOptions().get(0).getText());
      System.out.println(pickupTime.getAllSelectedOptions().get(0).getText());
    } catch (Exception e) {
      e.printStackTrace();
    }

I have validated the x-path in Mozilla browser while utilizing JDK 8. The Maven dependencies for the project are outlined below:

<dependencies>
    <!-- https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager -->
    <dependency>
        <groupId>io.github.bonigarcia</groupId>
        <artifactId>webdrivermanager</artifactId>
        <version>4.4.3</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.141.59</version>
    </dependency>

    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.9.10</version>
        <scope>test</scope>
    </dependency>

</dependencies>

Answer №1

There is an issue where the dropdowns are being covered by a chatbox that appears a few seconds later.

To address this problem, we have located the elements for the dropdowns using XPath:

WebElement ele1 = driver.findElement(By.xpath("((//select[@class='form-control  '])[2])"));
WebElement ele2 = driver.findElement(By.xpath("((//select[@class='form-control  '])[3])"));
WebElement ele3 = driver.findElement(By.xpath("((//select[@class='form-control  '])[4])"));

We then create Select objects and populate a list with the options available in the dropdown:

Select select2 = new Select(ele1);
List<WebElement> selectAdd = new ArrayList<WebElement>();

In order to interact with the chatbox, we utilize WebDriverWait to wait for it to be clickable before clicking on it:

new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//*[name()='svg' and @class='drift-default-icon drift-default-icon--chat-round']"))).click();

Finally, we loop through the dropdown options and add them to our list, printing out the total size at the end:

for(WebElement e : select2.getOptions()) {
            selectAdd.add(e);       
        }
System.out.println("Size is : "+selectAdd.size());

**Output:**
Starting ChromeDriver 91.0.4472.101 
(af52a90bf87030dd1523486a1cd3ae25c5d76c9b-refs/branch- 
heads/4472@{#1462}) on port 4516
Only local connections are allowed.
INFO: Found exact CDP implementation for version 91

2021-06-07
2021-06-09
2021-06-11
2021-06-12
Size is : 5
        
        

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

Using Javac to compile an entire Selenium project for Jenkins

Context: I am currently utilizing jUnit for executing Selenium tests. My goal is to automate running these tests with Jenkins on a nightly basis. Successfully, I am able to fetch my test and source files every night, build, and install the product. In orde ...

Creating dynamic connections between Plain Old Java Objects (POJOs) and RESTful APIs through automated

I have a POJO class that requires me to access a RESTful web service using specific properties from the POJO as parameters. The challenge lies in not knowing the endpoint and its parameters until runtime. Essentially, the user will set up the endpoint, i ...

Can Selenium execute actions simultaneously like asyncio?

As a newcomer here, I may make some mistakes in my description, so please bear with me. Currently, I have a form that consists of 10 textboxes, 5 dropdowns, and 2 date and time fields. My goal is to fill out all these fields simultaneously and then click ...

Utilizing Selenium IDE for generating a Facebook group editor (redactor) or a text input field within a div

I am facing an issue with adding text to a specific section in my HTML code, which is meant to be the description for a Facebook event. I have tried various methods like using a div or span element, but I believe this might require a redactor tool (althoug ...

Looking to perform a single step using Selenium WebDriver?

I have been utilizing selenium webdriver for automating web applications in Eclipse. In one of my tests, I am facing an issue where filling fields through a drop down is not working properly after navigating through multiple pages. My concern is that ever ...

Selenium running on AWS Device Farm is facing difficulty in locating an element using xpath

Having recently started using ADF, I am working on hybrid test scripts and have encountered an issue with finding elements through their xpath on Amazon Device Farm Appium JUnit. I have successfully implemented the following: action.click(By.id("menu"), ...

Guide to executing drag and drop functionality within an svg element using selenium?

[The image below shows a page element that I am trying to drag and drop into an SVG element. I have attempted using the action class and robot class, but have not been successful. resizeblockTwo']"> <div class="chartCanvas js-resizeblockOne d ...

Translating a PHP POST request into Java code

I am currently facing an issue with a PHP script that successfully makes a POST request to an old server (that I cannot access). My task now is to develop a REST API in Java/Spring to handle all interactions with this outdated server. However, my efforts a ...

Is it possible to integrate Scrapy with the Chrome Browser?

Scraping a web page that utilizes javascript-rendered AngularJS can be tricky. The developers of the site have implemented a feature to detect Safari/Firefox in private browsing mode and prevent scraping. Interestingly, this warning does not appear when us ...

Exploring spring-data-mongodb: searching for documents using various attributes and their values

In my mongodb database, I have the following document: { "_id" : "840e922e-05e0-4e4d-b574-303a72425bdd", "_class" : "com.document.domain.Doc", "type" : "User", "name" : "steven", "index" : 0, "data" : "This is sample user", "pr ...

Automating web elements with Python's Selenium by iterating through child elements

https://example.com/image.png What is the best way to iterate through the elements in "ctbdy" and verify if the combination of "bl_name bln_end" equals to "Materials"? ...

Is it possible to retrieve the name of the current test method being executed in testNG and incorporate it into the filename of a screenshot if the test fails, even if in a separate class?

Utilizing the Reflection Method Class or the ITestResult Class, I am able to retrieve the name of the test currently in progress. @AfterMethod public String fetchCurrentTestName(ITestResult result) { return result.getName(); } ...

Python: Issue with defining global variable

I'm attempting to execute the following code: import unittest import wd.parallel from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait from selenium.common.exceptions import WebDriverException import copy class Selen ...

Using JavaScript in Selenium, you can check a checkbox and verify whether it is checked

How can I select a checkbox and determine if it is checked using JavaScript, Selenium, and Node.js? I have attempted to use the .click method on the element and also tried native JavaScript code, but unfortunately it has not worked for me. driver.findElem ...

Tips for selecting a value from a list with Selenium in Python

A sample list structure is shown below: <span class="trigger"> <i class="fa fa-list-ol fa-lg"></i> <span>&ensp;1000 rows&emsp;</span></span> <div id="tool-row-menu" class="m ...

Assistance with offsetting a jQuery drop down menu

This is the third jQuery script that I've been working on. While parts of it have been inspired by other scripts, I'm now focusing on implementing a specific feature. I've dedicated 4 hours to solving the issue of displaying the submenu on ...

Eclipse is throwing a "Source not found" error during the debugging process

While debugging my code, I encountered the following error: When I set a breakpoint and try to debug, it throws a 'source not found' error. I have already clicked on "Edit Source Lookup Path" in Eclipse and added my project, but unfortunately, i ...

Encountering ElementNotInteractableException while using Selenium in Java to send Arrow Up to a number input

When trying to input a salary into a tax calculator website, I encountered an issue where an arrow_up or arrow_down key needed to be pressed in order for the tax amounts to be calculated instead of using the enter key. Despite researching online and findin ...

Is there a way to properly set a JsonNode in Mongo without converting it to a String using Jackson in Java?

After receiving a Json response from my server, I process it like a JsonNode { "results": [], "metadata": { "total_hits": 0, "max_score": 0 } } I then convert it into a String and store it in the MyProccesResponse field of my mongo database. How ...

Cucumber is failing to execute examples, and the web page is not being initiated properly

public class Applicant_Login_StepDef { WebDriver driver; @Given("^the URL$") public void the_URL() throws Throwable { System.setProperty("webdriver.chrome.driver", "C:\\Users\\SSMP&bs ...