The constructor webdriverwait(webdriver, int) is undefined

The error message “the constructor WebDriverWait(WebDriver, int) is undefined” indicates that you are trying to create an instance of the WebDriverWait class with parameters that do not match any of its available constructors.

The WebDriverWait class in Selenium is used to wait for a certain condition to be met before proceeding with further code execution. It allows you to specify a timeout duration and a webdriver instance to wait for.

There are several overloaded constructors available for WebDriverWait, but the one you are trying to use is not found. Let’s look at an example of how to correctly use WebDriverWait:


import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class ExampleClass {
  public static void main(String[] args) {
    // Set the path to the chromedriver executable
    System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");

    // Create a new instance of the ChromeDriver
    WebDriver driver = new ChromeDriver();
    
    // Navigate to a webpage
    driver.get("https://example.com");

    // Instantiate WebDriverWait with the webdriver and timeout duration
    WebDriverWait wait = new WebDriverWait(driver, 10);
    
    // Wait until an element is visible
    WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("exampleId")));
    
    // Perform further actions on the element
    // ...

    // Close the browser
    driver.quit();
  }
}
  

In this example, we first set the path to the chromedriver executable and create a new instance of the ChromeDriver. We then navigate to a webpage using the get() method of the driver.

Next, we create a new WebDriverWait instance with the driver and a timeout duration of 10 seconds. We use the until() method of WebDriverWait along with the ExpectedConditions class to wait until a specific element with the id “exampleId” is visible on the webpage.

Finally, we can perform further actions on the element once it is visible. In this case, we terminate the program by calling the quit() method on the driver to close the browser.

Make sure you have imported the necessary classes and that you are using the correct version of the Selenium WebDriver library.

Read more

Leave a comment