Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium WebDriver throwing an error for Click action, but Click is actually successful

When running synthetic browser tests using Selenium and Google Chrome, we intermittently receive a Selenium error (see below) on a particular website. The flow is:

  1. Load the start page
  2. Enter a search term
  3. Take a screenshot
  4. Click the search button
  5. Take a screenshot of the results

The error occurs during the click action (step 4), but the final screenshot (step 5) contradicts this and shows the search to have been initiated (only possible via a click - some form of auto search is not implemented on the website) and returned results.

Error:

Curl error thrown for http POST to /session/a4ec9662-1841-4809-9680-caf532b243b7/element/2/click
Operation timed out after 30001 milliseconds with 0 bytes received

Stack:

  • Selenium/Chrome Docker container: selenium/standalone-chrome:3.0.1-germanium
  • Facebook PHP WebDriver: see on GitHub
  • Docker PHP: see on GitHub

I have found another post regarding this that suggested to set this environment variable to the docker container: DBUS_SESSION_BUS_ADDRESS=/dev/null, however, this has not worked.

How we manage the container from code:

$Docker = new Docker();
$Manager = $Docker->getContainerManager();
$Container = $Manager->find($container_name);

if ($Container) {
    if ($Container->getState()->getRunning()) {
        // Restart container based on some logic around runtime and usage
    } else {
        $Manager->start($Container->getId());
    }
}

How we handle 'click' actions:

$Element = $this->WebDriverSession->findElement(By::cssSelector($css_selector));
if ($Element->isDisplayed()) {
    $Element->click();
}

EDIT:

I've upgraded our Selenium container to 3.4.0-einsteinium and am still seeing issues.

We have always had issues with some target websites not loading first time and Selenium throwing this error...

Curl error thrown for http POST to /session/cd18695c-bf88-482f-998e-4d8039c22359/url

...we get around this by catching that error and retrying x times before giving up. This update hasn't fixed this either.

like image 504
yippeykeiyay Avatar asked Aug 11 '17 10:08

yippeykeiyay


People also ask

How does Selenium verify a click?

To verify, if the element can be clicked, we shall use the elementToBeClickable condition. A timeout exception is thrown if the criteria for the element is not satisfied till the driver wait time.

Why does Selenium click fail?

Selenium clicks fail when an element is not attached to the current page. Re-find the element if the previously found element has been detached.

What is alternative for click in Selenium?

Alternative of click() in Selenium We can use the JavaScript Executor to perform a click action. Selenium can execute JavaScript commands with the help of the executeScript method. The parameters – arguments[0]. click() and locator of the element on which the click is to be performed are passed to this method.


1 Answers

The same kind of error is reported in docker-selenium issue 163, and seems related to selenium alone.
That is why there now (Aug. 2017) is SeleniumHQ/selenium issue 4384 (now Oct. 2017 closed, as a "performance issue").

That error was also seen in docker-selenium issue 20 (2015) with this comment, more about Chrome crashing:

  • Started in privileged mode:

    docker run --privileged
    
  • Fix small /dev/shm size

    docker exec $id sudo umount /dev/shm
    docker exec $id sudo mount -t tmpfs -o rw,nosuid,nodev,noexec,relatime,size=512M tmpfs /dev/shm
    

Update End 2017: issue 163 mentions

Maybe there is a bug in supervisord, you can try to bump the version or even go back to an older one.

like image 94
VonC Avatar answered Oct 21 '22 08:10

VonC