1

I'm having trouble with a click() function in my php code. It always throws this exception:

Fatal error: Uncaught Facebook\WebDriver\Exception\UnknownCommandException: POST /session/f3cffab9-71ad-4e0a-baab-4a46d807ce3d/element//click

I'm running it on:

  • windows 2008 server x64
  • selenium standalone server 3.9.1
  • PHP 7.1

But it doesn't work with 7.0 or 7.2 either. I'm using the newest facebook webdriver and the newest IEdriver as well.

The code I'm trying to run is:

<?php

use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Facebook\WebDriver\WebDriverBy;
use Facebook\WebDriver\WebDriverDimension;
use Facebook\WebDriver\WebDriverExpectedCondition;
use Facebook\WebDriver\WebDriverPoint;

require_once __DIR__ . '/vendor/autoload.php';

$host = 'http://localhost:4444/wd/hub';

$driver = RemoteWebDriver::create($host, DesiredCapabilities::InternetExplorer());

// Set size
$driver->manage()->window()->setPosition(new WebDriverPoint(0,0));
$driver->manage()->window()->maximize();
$driver->get("http://www.google.com");
sleep(1);

$driver->findElement(Facebook\WebDriver\WebDriverBy::name('q'))->click();
sleep(1);
$driver->findElement(Facebook\WebDriver\WebDriverBy::name('q'))->sendKeys('test');
sleep(1);

// Click the search button
$driver->findElement(Facebook\WebDriver\WebDriverBy::name('btnK'))->click();
$driver->quit();

?>

If I'm understanding everything correctly it should go to google, select the search bar and put the string "test" in there. Then it should select the submit button and submit the form. I've tried different sites as well as different commands and it seems like I can do everything but click and sendKeys. I also tried it with the newest Firefox and geckodriver and got the same result.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Mikop Rod
  • 11
  • 6

4 Answers4

1

This error message...

Fatal error: Uncaught Facebook\WebDriver\Exception\UnknownCommandException: POST /session/f3cffab9-71ad-4e0a-baab-4a46d807ce3d/element//click

...implies that the click() method failed.

If you examine the HTML DOM of Google Home Page through development tools, you will observe the Locator Strategy which you have used as:

Facebook\WebDriver\WebDriverBy::name('btnK')

doesn't identifies the Google Search button uniquely but it identifies 2 different elements.

Snapshot:

GoogleSearchButton

As per the rendering of DOM Tree the desired element doesn't receives the click.


Solution

As an alternative you can use either of the following Locator Strategies:

  • cssSelector:

    div[class]:not([jsname])>center>input[name='btnK']
    
  • xpath:

    //div[@class and not(@jsname)]/center/input[@name='btnK']
    

PS: Consider updating Selenium to current levels Version 3.141.59.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • 1
    Thanks for bringing that up, it turned out not to be THE issue however it helped me out with further investigation. – Mikop Rod Aug 29 '19 at 07:23
  • I posted answer to the original question above. Your answer, while it was helpful, didn't answer the original question. – Mikop Rod Aug 29 '19 at 07:43
0

As the error message as shown below states the WebDriver command is not known:

Fatal error: Uncaught Facebook\WebDriver\Exception\UnknownCommandException: POST /session/f3cffab9-71ad-4e0a-baab-4a46d807ce3d/element//click

When you correctly check the end-point for the POST request you will notice that there is a double slash. Instead it should be "element/click".

So this is a bug in the Facebook's webdriver client, and as such will fail with any driver. Are you really using the newest version of the client? Checking the current source on Github it seems to be all fine, and the code hasn't been changed for nearly 3 years.

Henrik
  • 249
  • 1
  • 6
  • I used composer to install the facebook webdriver and I indeed am using the 1.7.1 version which happens to be the latest. I checked the library itself and it is the same as the one you pointed at. Could it be that there is no ":id" in the middle of the slashes? Am I not selecting anything? – Mikop Rod Aug 28 '19 at 09:39
0

Well I solved my issue, it turned out to be little bit more complex. There was no problem with the click() function itself but rather with the findElement() function. There was a problem with the library itself. It expects ELEMENT as an index in $raw_element while the webdriver itself returns element-with-some-id as an index. Editing the library as follows...

public function findElement(WebDriverBy $by)
    {
        $params = ['using' => $by->getMechanism(), 'value' => $by->getValue()];
        $raw_element = $this->execute(
            DriverCommand::FIND_ELEMENT,
            $params
        );
        //my code
        return $this->newElement(reset($raw_element));
        //end of my code
    }

...solved the problem in this case, however it should be noted that every function that relies on this $raw_element variable will need to be edited in order for it to work properly. Thanks everyone for helping me out on this one.

UPDATE

Now that I fully understand the problem, it is caused by webdriver using W3C protocol. If you want to evade this issue eigher use chrome and chromedriver, or downgrade your driver to an old version (back in 2017).

Mikop Rod
  • 11
  • 6
0

In my case what solved the issue was simply upgrading old facebook/webdriver (version 1.6.0) to latest php-webdriver/webdriver (version 1.8.2).