Tips for choosing a dropdown option using Selenium WebDriver?

I am attempting to automate the selection of a drop-down menu using Selenium WebDriver.

Below is the code snippet I have written:

package Select;

import org.testng.annotations.Test;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.jetty.html.Select;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import org.openqa.selenium.support.ui.Select;

public class NewTest {


    public WebDriver driver= new FirefoxDriver();

    @BeforeTest
    public void setup(){
        //Open URL in Browser
        driver.get("http://www.homeshop18.com/"); 
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); 
        // Maximize the window.
        driver.manage().window().maximize();
    }


    @Test 
    public void EnterData(){
        Select select = new Select(driver.findElement(By.xpath("//[@id='q_category']")));
        select.deselectAll();
        select.selectByVisibleText("15095");

    }

}

However, I encountered the following error:

The constructor Select(WebElement) is undefined

Answer №1

The reason for this error is that you have imported a different Select class than the one required.

To resolve this issue, please remove the following statement from your imports:

import org.openqa.jetty.html.Select; // Remove this line

In order to work with the Select WebElement, you should import the Select class from Selenium:

import org.openqa.selenium.support.ui.Select; // Use this instead

I hope this solution helps!

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

The latest version of chromedriver.exe for .Net, version 2.36, is not functioning properly with chrome 64

Last year everything was working fine, but recently when I tried to run the program, I encountered an annoying error message: "chromedriver.exe has stopped working". The exception thrown was: OpenQA.Selenium.WebDriverException: 'An exception with a nu ...

Methods for extracting test data from Excel using Selenium

Currently, I am attempting to extract test data from an excel file for use in the sendkeys method. However, upon running my code, I encountered an error at this line: FileInputStream file = new FileInputStream (new File("C:\\Documents and Setting ...

Deconstructing a JSON Structure

I'm currently developing a D3 damage per second (DPS) calculator and encountering an issue with a JSON object. The JSON object I receive looks like this: {"Sockets":{"min":1,"max":1}, "Dexterity_Item":{"min":165,"max":165}, "Durability_Cur":{"min":58 ...

Discover the simple steps to integrate a timezone dropdown feature into your WordPress website using the Contact Form 7 plugin

I am designing a website and I need to implement a query form with a customizable time zone selection. Are there any specific steps to add a time zone drop-down menu using Contact Form 7? Here is the desired result I'm aiming for: Your assistance wil ...

Ensure that a TestNG test is reliant on the successful completion of a previous test

I have a set of Selenium TestNG tests written in Java, where the success relies on an initial test that registers a user and completes a tutorial. Subsequent tests use the login credentials from this first test. Despite implementing retry logic (IRetryAna ...

Uncovering the Secrets: Mastering Hidden Elements in Web Driver (Selenium 2)

When using my application, I have noticed that a specific element only becomes visible when I move my mouse cursor to a certain place in the GUI. This element can then be operated on by clicking a button. The problem arises when trying to automate this pr ...

Image capture by automation

I'm in the midst of a project automating tasks, where I have designed a basic program to generate testing reports and capture screenshots. package ReportTest; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; im ...

When attempting to execute Selenium WebDriver with a customized Firefox profile, an error message is thrown: "WebDriver

Attempting to initiate a selenium test with the given command: selenium-side-runner --server http://127.0.0.1:4444/wd/hub --debug -c "browserName='firefox' moz:firefoxOptions.args=[-profile, /home/seluser. /firefox-profile/myprofile]" --outp ...

Automating the process of navigating through pagination links using Selenium WebDriver's sets

I am new to using Selenium and I encountered a unique situation while scraping a website (page). The website does not have a traditional next page button for pagination. Instead, the pages change only when you click on the "..." option to reveal the next s ...

What sets DesiredCapabilities and RequiredCapabilities apart from each other?

Could anyone provide some insight into the contrast between DesiredCapabilities and RequiredCapabilities when used in the RemoteWebDriver constructor? If you need more information on the constructor, you can refer to this link: ...

Selenium's click() function is functioning properly, however, the submit() function is not working

During my Selinium Webdriver tests, I have encountered a puzzling issue where I am unable to submit a form by using the submit() method on the elements within the form. However, I can successfully submit the form by calling click() on the submit button. To ...

Internet Explorer node connected to a Selenium hub

Can Selenium Hub be utilized with an Internet Explorer node? I have successfully used Selenium Hub with Firefox and Chrome nodes using Docker and Kubernetes with the images available at . However, I cannot find an Internet Explorer image on Selenium' ...

What is causing the delay in retrieving elements using getX() method in Selenium?

Recently, I've been experimenting with web scraping using Selenium. However, I've noticed that there is a delay when calling getText(), getAttribute(), or getTagName() on the WebElements stored in an ArrayList from the website. The website I&apo ...

Select all elements in a column using Selenium in C# when two specific conditions are satisfied (Multiple Conditions)

My task is to extract all elements from the td of an HTML table. However, when I attempt to locate elements by xpath with multiple conditions, it fails and retrieves 0 elements. I have no issues retrieving all values with a single condition, indicating tha ...

Finding a specific number of records from an array of objects that also contain their own arrays can be achieved by using a combination of

I need a way to retrieve the last record from an ArrayList, but I'm facing a challenge because my ArrayList consists of a custom POJO class with its own array. This makes it difficult for me to determine the total number of records in the ArrayList. ...

Even with the correct Step Definition in place, Cucumber is struggling to locate it

While setting up the Selenium Cucumber framework, I encountered a problem. Even though the step definition path is correctly defined in the glue, it somehow cannot locate the cucumber step definition. Here are the installed jars: Cucumber-java, Cucumber-c ...

The specified selector is invalid or illegal in HTMLUnit

Attempting to mimic a login using htmlunit has presented me with an issue despite following examples. The console messages I have gathered are as follows: runtimeError: message=[An invalid or illegal selector was specified (selector: '*,:x' erro ...

What is the best method to track the total duration of a while loop nested within a for loop?

I am working on a project where I need to track the number of attempts made by a conditional while loop nested inside a for loop. This is to ensure the stability of the while-looping action and test its reliability through repeated testing. (using Selenium ...

Tips for maintaining login status following a test using PHPUnit, Selenium, and php-webdriver

My goal is to execute multiple tests with a shared session, all starting with a login process. <?php class ExampleTest extends PHPUnit_Framework_TestCase { /** * @var \RemoteWebDriver */ protected $webDriver; ...

Ways to address conflicting getter definitions for a property in Jackson when the source code is not accessible

Encountering an issue that states: HTTP Status 500 - Could not write JSON: Conflicting getter definitions for property "oid" The root cause is the presence of two similar methods in the class: getOID (deprecated) and getOid Unfortunately, modi ...