For C# there is a way to write a statement for waiting until an element on a page appears:
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
IWebElement myDynamicElement = wait.Until<IWebElement>((d) =>
{
return d.FindElement(By.Id("someDynamicElement"));
});
But is there a way to do the same in phpunit's selenium extension?
The only thing I've found is $this->timeouts()->implicitWait()
, but obviously it's not what I'm looking for.
This question is about Selenium2 and PHPUnit_Selenium2 extension accordingly.
The implicitWait
that you found is what you can use instead of waitForCondition.
As the specification of WebDriver API (that you also found ;)) states:
implicit - Set the amount of time the driver should wait when searching for elements. When searching for a single element, the driver should poll the page until an element is found or the timeout expires, whichever occurs first.
For example, this code will wait up to 30 seconds for an element to appear before clicking on it:
public function testClick()
{
$this->timeouts()->implicitWait(30000);
$this->url('http://test/test.html');
$elm = $this->clickOnElement('test');
}
The drawback is it's set for the life of the session and may slow down other tests unless it's set back to 0.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With