首先,我写我的场景:
search ipod
单击添加以比较每个发现的项目
这是我的代码(java webdriver pagefactory)
searchresultspage(我的对象页面)
@FindBy(id = "compare-total")
WebElement numberOfProductToCompare;
public void compareAllItems() {
for (WebElement compareButtons: compareButton) {
compareButtons.click();
}
}
public void areAllItemsClickedCompare() {
String text = numberOfProductToCompare.getText();
System.out.println(text);
}
我的主要考试班
@Test
public void addToCompare() {
searchresultspage.compareAllItems();
searchresultspage.areAllItemsClickedCompare();
}
我单击所有比较按钮,我想从链接Product Compare (4)
中获取数字,但是当我使用searchresultspage.areAllItemsClickedCompare();
时,则为System.out.println(text);打印我Product Compare (0)
,即使此方法是添加后进行比较(应该是Product Compare (4)
)也不知道该怎么办,一些建议?
认为,出现问题是因为Selenium在实例化类时捕获了compare-total
元素,但是当在页面上更新其内容时,它不会影响捕获的值。仅在单击所有复选框后,才尝试捕获compare-total
元素:
public void areAllItemsClickedCompare() {
WebElement numberOfProductToCompare = driver.findElement(By.id("compare-total"));
String dupa = numberOfProductToCompare.getText();
System.out.println(dupa);
}
driver
是您的WebDriver
实例。