Reputation: 11
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:
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.
Upvotes: 1
Views: 1776
Reputation: 46
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).
Upvotes: 0
Reputation: 11
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.
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).
Upvotes: 0
Reputation: 193378
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:
As per the rendering of DOM Tree the desired element doesn't receives the click.
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.
Upvotes: 1
Reputation: 259
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.
Upvotes: 0