Php-webdriver: unknown command: Cannot call non W3C standard command while in W3C mode for getLocationOnScreenOnceScrolledIntoView()

Created on 20 May 2020  路  2Comments  路  Source: php-webdriver/php-webdriver

What are you trying to achieve? (Expected behavior)

I'm trying to scroll down to the correct element using the $element->getLocationOnScreenOnceScrolledIntoView() method.

What do you get instead? (Actual behavior)

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

How could the issue be reproduced? (Steps to reproduce)

$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);

Details

  • Php-webdriver version: 1.8
  • PHP version: 7.4
  • Selenium server version: 3.9.1
  • Operating system: macOS Catalina
  • Browser used + version: Chrome 83.0.4103.61

Most helpful comment

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.

All 2 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

boussou picture boussou  路  6Comments

driesvints picture driesvints  路  7Comments

bscheshirwork picture bscheshirwork  路  4Comments

olleharstedt picture olleharstedt  路  4Comments

asofan picture asofan  路  8Comments