I have been working on a test case where all the elements checkbox, radio buttons are customized.( Replaced with images for better UI design and actual input elements are not visible). When I run click event on this element it gives me an error
Fatal error: Uncaught exception 'Facebook\WebDriver\Exception\ElementNotVisibleException' with message ' Build info: version: '3.0.1', revision: '1969d75', time: '2016-10-18 09:48:19 -0700' System info: . . . . . . . . . . . profile=UEsDBBQACAgIAHOClukXhoohJMbfGacAxIgasTKI4EoBxf8KHZPtZXeKrYFcXN+t in vendor\facebookwebdriver\lib\Exception\WebDriverException.php on line 117
Below is a snapshot of the code I am using.
$element = $driver->wait()->until(WebDriverExpectedCondition::presenceOfElementLocated(WebDriverBy::cssSelector($test_case['elementParams']['cssPath'])));
What can be the issue here? I have checked the same element click event using python and its working
Hello,
I think the element needs to be visible (sometimes elements are loaded on the page, but are not yet visible). I think you could use something like:
$locator = $test_case['elementParams']['cssPath'];
$secondsToWait = 30;
for ($second = 0; ; $second++) {
if ($second >= $secondsToWait) $this->fail("The locator is not visible: ($locator)");
try {
if ($this->driver->findElement(WebDriverBy::cssSelector($locator))->isDisplayed()) break;
} catch (NoSuchElementException $e) {}
sleep(1);
}
The actual element is not visible.
Check in below link, the checkbox is not visible, and is customized using css3
http://codepen.io/CreativeJuiz/pen/BiHzp
How can I click on that checkbox?
Hello,
As far as I know you can't click on elements that are not visible. But you can run a javascript to click on them and it will work:
$driver->executeScript('document.getElementById(\'test1\').click();');
Most helpful comment
Hello,
As far as I know you can't click on elements that are not visible. But you can run a javascript to click on them and it will work:
$driver->executeScript('document.getElementById(\'test1\').click();');