我试图在我的构造函数中声明显式等待,但出现错误类型不兼容。如何解决。关于selenium wait的问题
I am trying to declare explicit wait in my constructor, but getting error incompatible types. How to solve it. Question related to selenium wait
package PageObject;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.ui.WebDriverWait;
public class Amazon {
WebDriver driver;
WebDriver wait;
public Amazon(WebDriver driver){
this.driver = driver;
PageFactory.initElements(driver, this);
wait = new WebDriverWait(driver, 20);
}
@FindBy(xpath = "//input[@type = 'text']")
WebElement search;
这是我的代码,我在行 wait = WebDriverWait(driver, 20); 中遇到错误
错误是 Incompatible Type, Required : org.openqa.selenium.WebDriver, Found : org.openqa.selenium.support.ui.WebDriverWait
在以前的代码中尝试过,但从未遇到过这样的错误。也导入了必要的库,但无法解决。如果有人可以帮助解决错误。我不想使用 Fluent 等待或 thread.sleep。我希望通过显式等待本身解决错误
这个
WebDriver wait;
应该是
WebDriverWait wait;
WebDriverWait
是一个 class,而您正在像这样创建 class 的对象,因此您应该声明相同的 class.
wait = new WebDriverWait(driver, 20);
完整代码应该是:
package PageObject;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.ui.WebDriverWait;
public class Amazon {
WebDriver driver;
WebDriverWait wait;
public Amazon(WebDriver driver){
this.driver = driver;
PageFactory.initElements(driver, this);
wait = new WebDriverWait(driver, 20);
}
@FindBy(xpath = "//input[@type = 'text']")
WebElement search;
请像下面这样更改。 wait
应声明为 WebDriverWait
而不是 WebDriver
WebDriver driver;
WebDriverWait wait;
public Amazon(WebDriver driver){
this.driver = driver;
PageFactory.initElements(driver, this);
wait = new WebDriverWait(driver, 20);
}
package PageObject;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.ui.WebDriverWait;
public class Amazon {
WebDriver driver;
WebDriver wait;
public Amazon(WebDriver driver){
this.driver = driver;
PageFactory.initElements(driver, this);
wait = new WebDriverWait(driver, 20);
}
@FindBy(xpath = "//input[@type = 'text']")
WebElement search;
这是我的代码,我在行 wait = WebDriverWait(driver, 20); 中遇到错误 错误是 Incompatible Type, Required : org.openqa.selenium.WebDriver, Found : org.openqa.selenium.support.ui.WebDriverWait 在以前的代码中尝试过,但从未遇到过这样的错误。也导入了必要的库,但无法解决。如果有人可以帮助解决错误。我不想使用 Fluent 等待或 thread.sleep。我希望通过显式等待本身解决错误
这个
WebDriver wait;
应该是
WebDriverWait wait;
WebDriverWait
是一个 class,而您正在像这样创建 class 的对象,因此您应该声明相同的 class.
wait = new WebDriverWait(driver, 20);
完整代码应该是:
package PageObject;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.ui.WebDriverWait;
public class Amazon {
WebDriver driver;
WebDriverWait wait;
public Amazon(WebDriver driver){
this.driver = driver;
PageFactory.initElements(driver, this);
wait = new WebDriverWait(driver, 20);
}
@FindBy(xpath = "//input[@type = 'text']")
WebElement search;
请像下面这样更改。 wait
应声明为 WebDriverWait
而不是 WebDriver
WebDriver driver;
WebDriverWait wait;
public Amazon(WebDriver driver){
this.driver = driver;
PageFactory.initElements(driver, this);
wait = new WebDriverWait(driver, 20);
}