我正在尝试用java在eclipse中使用Selenium 4的特性,但似乎不能让它们工作,我想这一定是我在配置上的错误,所以如果有人能解释我哪里出了错,以及我如何纠正它,我将不胜感激。
下面的代码:我在最后一行(包含newWindow()方法)收到错误警告,错误消息与本文的标题一致。我已经从这里下载了selenium- java -4.0.0- https://selenium-release.storage.googleapis.com/index.html?path=4.0-alpha4/ -4我已经创建了一个新的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
}
}发布于 2021-06-17 20:49:31
可能有两个问题:
1)不正确的导入-您应该导入以下内容:
org.openqa.selenium.WindowType;
2)您使用的版本存在问题。尝试升级selenium版本。
版本:
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/
https://stackoverflow.com/questions/67973051
复制相似问题