0

我正在尝试使用 java 在 eclipse 中使用 Selenium 4 功能,但似乎无法让它们工作,我假设这一定是我的配置错误,所以如果有人能解释我的位置,我将不胜感激我出错了,我该如何纠正?

下面的代码:我在最后一行(包含 newWindow() 方法)收到错误警告,错误消息与本文标题一致。我已经从这里下载了 selenium-java-4.0.0-alpha-4 https://selenium-release.storage.googleapis.com/index.html?path=4.0-alpha4/ 我创建了一个新的 eclipse java项目,并在我的 java 构建路径中解压缩并包含所有 jar 文件,但它似乎无法识别/或无法找到 newWindow() 方法

package practice;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.WindowType;
import org.openqa.selenium.chrome.ChromeDriver;
import static org.openqa.selenium.support.locators.RelativeLocator.withTagName;
import org.openqa.selenium.By;

public class Sel4alpha4 {

    public static void main(String[] args) {
        System.setProperty("webdriver.chrome.driver","C:\\Users\\me\\Downloads\\chromedriver_win32\\chromedriver.exe");
        WebDriver driver = new ChromeDriver();
        driver.get("http://www.google.com");
        driver.switchTo().newWindow(WindowType.TAB); // this line has the error 
    }
}
4

1 回答 1

0

可能有两个问题:

1)不正确的导入-您应该导入以下内容:

org.openqa.selenium.WindowType;

2)您使用的版本有问题。尝试升级硒版本。

版本:

selenium 4.0.0-beta-4

请尝试从以下链接下载更新的 jar:

https://www.selenium.dev/downloads/

或者

https://selenium-release.storage.googleapis.com/index.html?path=4.0-beta-4/

于 2021-06-17T12:49:30.947 回答