module-webdriver icon indicating copy to clipboard operation
module-webdriver copied to clipboard

`click()` doesn't find `<summary>`, `<label>`, or elements inside `<a>`

Open ThomasLandauer opened this issue 5 years ago • 4 comments

The HTML5 element <summary> is missing from the list of clickable elements at WebDriver::_findClickable()

I tried to add it there just like the others: ".//summary[normalize-space(.)=$locator]", - but this doesn't really fix it, since there are many elements allowed inside <summary>: https://html.spec.whatwg.org/#the-summary-element

I think this needs to be refactored, since (from looking at the code) elements inside <a> are also not matched, e.g. <a href="..."><div>...</div></a> - which is valid HTML 5: https://html.spec.whatwg.org/#the-a-element

So I guess the arguments that are thrown into Locator::combine() need to be replaced by functions to allow more complex matching logic.

ThomasLandauer avatar Sep 13 '20 15:09 ThomasLandauer

Workaround: You need to identify the element by some attribute (not by its text content), e.g.:

$I->click(['css' => 'details[id="foo"] summary']);

ThomasLandauer avatar Sep 13 '20 15:09 ThomasLandauer

Clicking on a <label> by its text isn't working too (see https://github.com/Codeception/module-webdriver/issues/21 for the reason I tried it).

I tried to fix it by adding this to WebDriver::_findClickable():

".//label[normalize-space(.)=$locator]"

...but I'm getting this error in the console:

[Facebook\WebDriver\Exception\ElementNotInteractableException] element not interactable (Session info: chrome=85.0.4183.83)

ThomasLandauer avatar Sep 21 '20 22:09 ThomasLandauer

Also, it looks like elements inside <details> are always treated as they can be seen (i.e. dontSeeElement() fails), no matter if the <details> is open or not. But I haven't investigated this further.

ThomasLandauer avatar Nov 17 '20 22:11 ThomasLandauer

Workaround for seeElement() and dontSeeElement() with <details>:

$open = $I->grabAttributeFrom(['css' => 'details.foo'], 'open');
// Assert that <details> is closed:
$I->assertNull($open);
// Assert that <details> is open:
$I->assertSame('true', $open);

ThomasLandauer avatar Sep 22 '21 14:09 ThomasLandauer