<a class="lnk" href="http://www.google.com">Go Google</a>
When click on this link, another css class 'loading' will append. How do we test this before redirecting to google.com.
$element = $driver->findElement(WebDriverBy::className('lnk'));
$element->click();
Is there any way to check the class attribute contains 'loading' before redirecting to destination?
You can use JavaScript to edit the href attribute and add it timeout
$element = $driver->findElement(WebDriverBy::className('lnk'));
$href = $element->getAttribute('href');
$script = "javascript:setTimeout( function() { window.location = {$href} }, 5000 );"
$driver->executeScript("arguments[0].setAttribute('href', arguments[1]);", $element, $script);
Now yo have enough time to check if class attribute contains loading
$element = $driver->findElement(WebDriverBy::className('lnk'));
$class = $element->getAttribute('class');
if (strpos($class, 'loading') !== false) { }
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