I am trying to automate some test cases using Java and Selenium WebDriver. I have the following scenario:
- There is a page named 'Products'. When I click on 'View Details' link in the 'Product' page, a popup (modal-dialog) containing the details of the item appears.
- When I click on the 'Close' button in the popup the popup closes and the page automatically refreshes (the page is just reloading, the contents remain unchanged).
After closing the popup I need to click on 'Add Item' button in the same page. But when WebDriver trying to find the 'Add Item' button, if the internet speed is too fast, WebDriver can find and click the element.
But if the internet is slow, WebDriver finds the button before the page refresh, but as soon as the WebDriver click on the button, the page refreshes and
StaleElementReferenceException
occurs.- Even if different waits are used, all the wait conditions become true
(since the contents in the page are same before and after reload)
even before the page is reloaded and
StaleElementReferenceException
occurs.
The test case works fine if Thread.sleep(3000);
is used before clicking on the 'Add Item' button. Is there any other workaround for this problem?