selenium icon indicating copy to clipboard operation
selenium copied to clipboard

Unable to interact with element that is present and enabled

Open eduardoreynoso opened this issue 7 years ago • 8 comments

🐛 Bug Report

Selenium is unable to interact with an element that is visible on the screen and enabled: The element is an input text field. When retrieved, the element shows positive values on the rectangle: image Querying for is_enabled() returns True But querying for is_displayed() returns False Trying to send any action to the element throws an exception: ElementNotVisible It has a unique identifier and there are no other elements that match. I noticed that this started happening when 2 specific CSS properties were added to the container of that element: overflow-y: auto; display: contents; This was added in order to display the element properly on Edge, but it broke the interaction on Chrome.

To Reproduce

Here is a short HTML with an example to reproduce the issue: https://jsfiddle.net/k594wjgu/2/

<html>
  <body>
  <form style="display: flex;
  flex-direction: column;
  display: contents;
  overflow-y: auto;">
    <input type="text" name="first_name"/>
  </form>
  </body>
</html>

Here is the code to reproduce (Uses Python selenium bindings)

from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://jsfiddle.net/k594wjgu/2/")
driver.switch_to.frame(self.driver.find_element_by_name('result'))
driver.find_element_by_name('first_name').is_enabled()
# ^ Returns True
driver.find_element_by_name('first_name').is_displayed()
# ^ Returns False, however if either display: contents; or overflow-y: auto is removed from the form style #then the statement returns True and I can send click or send key actions
driver.find_element_by_name('first_name').send_keys('Hello')
# ^ Throws ElementNotVisibleException

Expected behavior

I would expect that I can send actions to any element that is displayed on the viewport and that is enabled

Environment

OS: MacOS Mojave 10.14.1 Browser: Chrome Browser version: 72 Browser Driver version: 2.46 Language Bindings version: Python selenium 3.141.0 Selenium Grid version (if applicable): NA

eduardoreynoso avatar Feb 27 '19 23:02 eduardoreynoso

@eduardoreynoso : From your bug report it seems that you implicitly mean that this happens only on Chrome?

virenv avatar Mar 01 '19 02:03 virenv

@virenv I have not tested it on any other browser, it seems that its a CSS property thats affecting Selenium behavior. If you want I can try with the firefox driver, would that help?

eduardoreynoso avatar Mar 01 '19 18:03 eduardoreynoso

@eduardoreynoso : That would really help. The reason I am asking you for this information is that Selenium does not perform any CSS level checks on its side. It just requests for a particular action from the browser and inturn browser performs the checks. Here browser term is loosely used for both the real browser and Webdriver server.

In short, the checking is happening on the browser side. It would be really helpful if we know if this is impacting all browsers. The relevant part of the WebDriver standard is here: https://w3c.github.io/webdriver/#interactability, as far as I remember. Correct me if I am wrong.

virenv avatar Mar 02 '19 02:03 virenv

This occurs with Firefox as well, and is caused by the combination of "display: contents" and "overflow-: auto;" . I believe this is because an element with a display type of contents has no client rect in the document, and the visibility atom doesn't know how to handle that when trying to determine if the child is shown or not. The visibility atom will probably have to be updated to fix this.

twalpole avatar Mar 08 '19 19:03 twalpole

From a quick read of the JS atoms - I would guess the issue is probably the canBeOverflowed function at https://github.com/SeleniumHQ/selenium/blob/master/javascript/atoms/dom.js#L661 not correctly handling display: contents, although I haven't put in enough time to 100% confirm that.

twalpole avatar Mar 08 '19 20:03 twalpole

I've create PR #7013 that fixes this, however since 'display: contents' elements are ignored for layout purposes specifying overflow with it as well really makes no sense from a CSS pov.

twalpole avatar Mar 08 '19 23:03 twalpole

I encountered the same issue on safari.

smart625 avatar Mar 16 '19 09:03 smart625

PR #7013 merged

barancev avatar Mar 29 '19 21:03 barancev