Consider the following scenario:-
A bookstore website has number of books and each book has some details like author name, publisher, etc. The main page displays number of books and on clicking any book on the page a pop-up opens which displays details of that particular book. The main html page looks something like below.
link Book 1
<book id="abc">
<a href="linkAddress">link</a>
<div class="name">Book 2</div>
</book>
<book id="abc">
<a href="linkAddress">link</a>
<div class="name">Book 3</div>
</book>
<book id="abc">
<a href="linkAddress">link</a>
<div class="name">Book 4</div>
</book>
<book id="abc">
<a href="linkAddress">link</a>
<div class="name">Book 5</div>
</book>
I want to fetch details of all books so what I did is I fetched a list of all the book elements from the main page
List<WebElement> items = fireFoxDriver.findElements(By.id("abc"));
and then iterated through that list and clicked each element one by one to open a pop-up that shows details of the book
for(WebElement itemDetails : items){
itemDetails.click();
//After clicking the element pop-up opens which shows details of this particular book.
//Get details of this particular book from pop-up.
}
and fetched the details I required from that opened pop-up and then closed the popup after getting all required details and moved to next element.
Now the problem is that I am using itemDetails.click()
to open pop-up but sometimes I get the following errors when opening a pop-up window. I am not sure how to handle these errors so please guide me. Elements are there on the main page I am not changing the main page while opening pop-up but still getting DOM errors.
- org.openqa.selenium.StaleElementReferenceException: Element is no longer attached to the DOM
- com.thoughtworks.selenium.SeleniumException: Timed out waiting for action to finish
Thanks.