SELNEIUM 4.7.0抛出NoSuchMethod异常



我正在改变我的硒项目从3.141到4.7.0,但我看到NoSuchElementException在PageFactory初始化。

<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.7.1</version>
</dependency>
public WebElementsLogin(WebDriver driver) {
this.driver = driver;
PageFactory.initElements(this.driver, this);
}
java.lang.NoSuchMethodError: 'void org.openqa.selenium.support.PageFactory.initElements(org.openqa.selenium.SearchContext, java.lang.Object)'

使用selenium 4.7.1和JDK 11:

<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.7.1</version>
</dependency>
public class Google {
private WebDriver driver;
@FindBy(name = "q")
private WebElement searchField;

public Google(WebDriver driver){
this.driver = driver;
PageFactory.initElements(driver, this);
}
public  void searchFor(String text){
searchField.sendKeys(text);
searchField.sendKeys(Keys.ENTER);
}
public void navigateTo(){
driver.get("https://google.com");
}
public static void main(String[] args) {
WebDriverManager.chromedriver().setup();
WebDriver chrome = new ChromeDriver();
Google google = new Google(chrome);
google.navigateTo();
google.searchFor("Selenium");
}
}

一切正常

更正这行:

PageFactory.initElements(this.driver, this);

相关内容

  • 没有找到相关文章

最新更新