Skip to content

WebDriverExpectedCondition::elementToBeClickable does not consider CSS pointer-events: none #1111

@rr-it

Description

@rr-it

Bug description

WebDriverExpectedCondition::elementToBeClickable should check if an element is clickable.

Elements that have CSS pointer-events: none set are not clickable. This should be considered in the check for clickability.

Also see: SeleniumHQ/selenium#14427

How could the issue be reproduced

$I->waitForElementClickable('button');

using Codeception Module WebDriver v4.0.2

https://github.com/Codeception/module-webdriver/blob/ef0ea8044eb01dc1e830df27fe431e71440a462f/src/Codeception/Module/WebDriver.php#L2657-L2661

    public function waitForElementClickable($element, int $timeout = 10): void
    {
        $condition = WebDriverExpectedCondition::elementToBeClickable($this->getLocator($element));
        $this->webDriver->wait($timeout)->until($condition);
    }

Expected behavior

This should not select an element as follows:

HTML:

<button class="disabled"></button>

CSS:

.disabled {
    pointer-events: none;
}

Php-webdriver version

1.12

PHP version

8.3

How do you start the browser driver or Selenium server

Don't know - TYPO3 test environment

Selenium server / Selenium Docker image version

No response

Browser driver (chromedriver/geckodriver...) version

No response

Browser name and version

chrome-headless-shell=124.0.6367.118

Operating system

No response

Additional context

/**
* An expectation for checking an element is visible and enabled such that you can click it.
*
* @param WebDriverBy $by The locator used to find the element
* @return static Condition return the WebDriverElement once it is located, visible and clickable.
*/
public static function elementToBeClickable(WebDriverBy $by)
{
$visibility_of_element_located = self::visibilityOfElementLocated($by);
return new static(
function (WebDriver $driver) use ($visibility_of_element_located) {
$element = call_user_func(
$visibility_of_element_located->getApply(),
$driver
);
try {
if ($element !== null && $element->isEnabled()) {
return $element;
}
return null;
} catch (StaleElementReferenceException $e) {
return null;
}
}
);
}

Adding $element->getCSSValue('pointer-events') !== 'none' to the condition might give the expected result.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions