【发布时间】:2014-10-05 05:00:11
【问题描述】:
我收到一条错误消息。这个错误一般可以,但我无法在我的代码中解决它。有人可以帮我吗?
解释:
我从循环中获取航空公司代码,但是当if(){} 条件开始处理时。我收到一个错误
线程“main” org.openqa.selenium.StaleElementReferenceException 中的异常:元素不再附加到 DOM
这只是所有li 标签之一。 li标签总数为9个。
<li data-airline-id="SU">
<input id="airline_SU" type="checkbox" checked="checked" title="Aeroflot">
<label for="airline_SU" class="clearfix">
<span class="day-filters-label-price">$939</span>
<span class="day-filters-label-message">Aeroflot</span>
</label>
</li>
Java 代码:
ul = driver.findElements( By.xpath( "//div[@id='filters-airlines']//ul[@class='clearfix']/li" ) );
for( WebElement element : ul ){
String countryCode = element.getAttribute( "data-airline-id" );
System.out.println( countryCode );
if( !"DE".equals( countryCode ) ){
element.findElement( By.id( "airline_" + countryCode ) ).click();
}
try{
Thread.sleep( 1000 );
}
catch( InterruptedException e ){
// TODO Auto-generated catch block
e.printStackTrace();
}
}
【问题讨论】:
标签: selenium selenium-webdriver webdriver