如果该按钮不存在,则测试将挂起超过 5 秒。
方法findElement()
inDefaultElementLocator
被调用了 ~63 次!
块的嵌套越深,等待时间越长。
是否可以在 htmlElements 中以这种方式使用块?我究竟做错了什么?
@Test
public void myTestFunc() {
WebElement element = myPage.getMyForm()
.getSubForm()
.getButton()
.getWrappedElement();
try {
(new WebDriverWait(driver, 5))
.until(ExpectedConditions.visibilityOf(element));
} catch (Exception ex) {
ex.printStackTrace();
}
}
public class MyPage {
@FindBy(className = "...")
private MyForm myForm;
public MyPage(WebDriver driver){
PageFactory.initElements(new HtmlElementDecorator(driver), this);
}
public MyForm getMyForm() {
return myForm;
}
}
public class MyForm extends HtmlElement {
@FindBy(className = "...")
private MySubForm mySubForm;
public MySubForm getMySubForm() {
return mySubForm;
}
}
public class MySubForm extends HtmlElement {
@FindBy(className = "...")
private MyButtonWrap button;
public MyButtonWrap getButton() {
return button;
}
}
public class MyButtonWrap extends Button {
public MyButtonWrap(WebElement wrappedElement) {
super(wrappedElement);
}
// ...
}