I'm trying to scroll down to the correct element using the $element->getLocationOnScreenOnceScrolledIntoView() method.
When executing the method I get the following error: unknown command: Cannot call non W3C standard command while in W3C mode. In Facebook\WebDriver\Exception\UnknownCommandException
$element = $driver->findElement($by);
$element->getLocationOnScreenOnceScrolledIntoView();
I'm not sure if this is suppose to happen. The error states that I should create a none w3c compliant driver/session. I tried that as well, without luck. isW3cCompliant is always true. My original driver initialisation:
$options = new ChromeOptions();
$capabilities = DesiredCapabilities::chrome();
$capabilities->setCapability('chromeOptions', $options);
$capabilities->setCapability('goog:chromeOptions', [
'args' => [
'user-data-dir=', // Removed actual dir for this post
],
]);
// Create a new driver with a new session.
$driver = RemoteWebDriver::create($this->host, $capabilities);
Hi, you are using command, which is no longer supported in W3C WebDriver protocol (getLocationOnScreenOnceScrolledIntoView()) and you should use appropriate replacement, but it may also not be necessary to make this call altogether.
What is the purpose of using this call? What are you trying to achieve by this?
$element->getLocationOnScreenOnceScrolledIntoView();
You are not using the returned value (element location), so I guess you just want to scroll the webpage so that the element is in current view? Why? What do you execute right after the code you posted?
I fixed it using the following code:
$element = $driver->findElement($by);
$action = new WebDriverActions($this->driver);
$action->moveToElement($element);
$action->perform();
The reason why I need to scroll down is to get a certain element to show in the DOM. I've a large list with hundreds of items. The list loads the correct items to show based on your position. So I need to scroll down to be able to click on the element which I'm looking for.
Thanks for your help.
Most helpful comment
I fixed it using the following code:
The reason why I need to scroll down is to get a certain element to show in the DOM. I've a large list with hundreds of items. The list loads the correct items to show based on your position. So I need to scroll down to be able to click on the element which I'm looking for.
Thanks for your help.