Home > Mobile >  How to click element using java in selenium?
How to click element using java in selenium?

Time:08-12

Trying to click in element with a correct locator but i have problem is located here WebDriverWait(driver, 120) saying this error message The constructor WebDriverWait(WebDriver, int) is undefined

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;

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.chrome.ChromeOptions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

import java.io.IOException;

public class main {

    WebDriver driver;
    
    @BeforeTest
    public void BeforeSetUp() {
        ChromeOptions options = new ChromeOptions();
        options.addExtensions(new File("adblocker.crx"));
        driver = new ChromeDriver(options);
        options.addArguments("--disable-notifications");
        driver.manage().window().maximize();
    }
    
    @Test
    public void SetUp() throws IOException, InterruptedException {
        
        String fileName = "list.txt";
        String baseURL = "https://www.proxysite.com/";
        
        try (BufferedReader br = new BufferedReader(new FileReader(fileName))) {
            
            String line;
            
            while ((line = br.readLine()) != null) {
                
                driver.get(baseURL);

                WebElement button = (new WebDriverWait(driver, 120)).until
                (ExpectedConditions.elementToBeClickable(By.xpath("")));
                button.click();

                Thread.sleep(3000);

                WebElement button1 = new WebDriverWait(driver, 120).until
                (ExpectedConditions.elementToBeClickable(By.xpath("")));
                button1.click();
                
            }
            
        } catch (IOException e) {
            e.printStackTrace();
        }
        
    }
    
}

CodePudding user response:

@cbeb7f9edf , in the latest version of Selenium, you should create the WebDriverWait object as below:

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(120));
  • Related