Issue
I am writing a php script to test out a webpage with 2 drop down lists, the first dropdown gets populated as soon as the page is loaded
After list1 is populated, i have to select a value then the second list gets populated as well see attached image
With the PHP webdriver, i can easily select an option from the first dropdown list like so
$select = new WebDriverSelect($driver->findElement(WebDriverBy::id('make')));
$select->selectByIndex(2);
After i select an option from list1, i have to wait for the page to populate the second list i.e the Mode & Body list, for this is use below code
$driver->wait()->until(
WebDriverExpectedCondition::visibilityOf($driver->findElement(WebDriverBy::id('model')))
);
//model & body
$select = new WebDriverSelect($driver->findElement(WebDriverBy::id('model')));
$select->selectByIndex(2);
However, the webdriver doesn't seem to wait until the second list is populated, and therefore it throws an error saying the element is stale
How can i wait until the second list is populated before trying to access it ? I am using PHP Chrome webdriver on a windows machine
Solution
I had to use the refreshed
condition; to get the code working.
Here is a walkthrough of why this worked
The said method waits until an elements get repainted and refreshed
Here is a complete implementation
$driver->wait()->until(
WebDriverExpectedCondition::refreshed(WebDriverExpectedCondition::stalenessOf($driver->findElement(WebDriverBy::id('model'))))
);
Answered By - salimsaid
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.