[英]How to click element using java in selenium?
尝试使用正确的定位器单击元素但我有问题位于此处WebDriverWait(driver, 120)
说此错误消息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();
}
}
}
@cbeb7f9edf,在最新版本的 Selenium 中,您应该创建 WebDriverWait object,如下所示:
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(120));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.