我决定试用yandex HtmlElements框架来构建包含几个类似块的页面。目的是在单独的类中描述单个块及其所有方法,然后在主页中迭代它们的列表。
下面是来自https://github.com/yandex-qatools/htmlelements的示例,我做了以下说明:
科类
@FindBy(xpath = ".//div[@class='score-section']")
public class Section extends HtmlElement {
@Timeout(10)
@FindBy(xpath = ".//div[@class='account-title']")
private WebElement accountTitle;
public void printValues() {
System.out.println(accountTitle.getText());
}页面类
public class MainPage extends BasePage {
public MainPage(WebDriver driver) {
super(driver);
PageFactory.initElements(new HtmlElementDecorator(new HtmlElementLocatorFactory(driver)), this);
}
List<Section> sections;
public void iterateOverSections() {
for (Section section : sections) {
section.printValues();
}
}然而,我得到了NoSuchElementException的accountTitle。
这是可能的吗(以及如何实现?)从类似的块构建页面?
发布于 2016-05-23 08:47:58
我看不出你的代码有什么问题,你能显示你测试的html页面吗?
https://stackoverflow.com/questions/37351612
复制相似问题