I got an error message. This error general can be but I can't solve it in my code. Is can anyone help me?
Explanation:
I am taking airline code from in a loop, but when if(){}
condition start to process. I receive an error
Exception in thread "main" org.openqa.selenium.StaleElementReferenceException: Element is no longer attached to the DOM
This is just one of the all li
tags. The total number of li
tag is 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 Code:
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();
}
}