1
请参阅下面的部分代码:如何等待具有相同类名的所有元素?
public class OrderDetailsDashboard extends AbstractTestNGSpringContextTests {
By orderDetails = By.cssSelector(".col-md-12 span strong");
By orderMoreDetails = By.cssSelector(".row.panel-info-summary span strong");
By refundOrderButton = By.cssSelector(".refund-order-action");
public orderDetails getOrderDetails(WebDriver driver) {
logger.info("About to collect and returns the specific order details - refreshing page");
WebDriverWait waitForTitle = new WebDriverWait(driver,30);
try {
waitForTitle.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(orderMoreDetails));
}
catch (StaleElementReferenceException ex) {
waitForTitle.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(orderMoreDetails));
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
waitForTitle.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(orderDetails));
我有它似乎需要解决的问题,但我不满意的解决方案。 我“米试图用我的自动加载一个页面的下一个元素(这里表示为一个页面对象):
By orderDetails = By.cssSelector(".col-md-12 span strong")
,提出我的网页上6次,只包含了大胆的文字我已经注意到,当我试图获得第7个元素文本,我得到Index Out Of Bounds Exception
。尽管我使用wait()
方法。 最后,我意识到wait()
是等待,但不是所有元素被憎恨,这就是我的测试失败的原因。 (这也是我添加了thread.sleep
方法的原因)。
有没有什么办法可以使用wait()
方法实际等待ALL页面上的元素?
“在我的页面上显示下一个元素6次”如果页面中有* 6个*,并且您尝试获取第7个元素,那么您会遇到异常。你的意思是说,虽然Selenium *找到* 6,实际上有*比6多*。 – Louis 2014-09-02 16:14:37
当页面启动时,有7个元素具有相同的类名,我试图处理它们中的最后一个(第7个)。这就是为什么我要使用wait()方法,就在这里等待第一个元素的可见性,所以当我尝试应用到第七个元素时,我得到一个异常。这就是为什么我使用thread.sleep。我的问题是,如果有任何方法可以告诉硒实际上等待对于具有相同页面类名称的所有元素。 – 2014-09-03 08:30:05