1

I am trying to use Python Selenium to click a button on a webpage, but Selenium is giving exception "Element is not currently visible and so may not be interacted with".

The DOM structure is quite simple:

<body style="overflow: hidden;"> ... <div aria-hidden="false" style="display: block; ..."> ... <button id="button-aaa" aria-hidden="true" style="..."> ... </div> ... </body>

I have searched Google and Stackoverflow. Some users say Selenium cannot click a web element which is under a parent node with overflow: hidden. But surprisingly, I found that Selenium is able to click some other buttons which are also under a parent node with overflow: hidden.

Anyway, I have tried to use driver.execute_script to change the <body> style to overflow: none, but Selenium is still unable to click this button.

I have also tried to change the button's aria-hidden="true" to aria-hidden="false", but Selenium still failed to click.

I have also tried to add "display: block;" to the button's style, and tried all different combination of style changes, but Selenium still failed to click.

I have used this commands to check the button: buttonelement.is_displayed(). It always returns False no matter what style I change in the DOM. The button is clearly visually visible in the Firefox browser, and it is clickable and functioning. By using the Chrome console, I am able to select the button using ID.

May I know how can I check what is causing a web element to be invisible to Python Selenium?

userpal
  • 1,483
  • 2
  • 22
  • 38
  • This question will be difficult to answer without a concrete example to work with. – Steven Rumbalski May 12 '14 at 15:55
  • You can get page source using something like this: `browser.get(raw_input("Enter URL: ")) html_source = browser.page_source `, then proceed from there. – Richard May 12 '14 at 16:18
  • afaik, overflow can get only five values (overflow: auto | hidden | scroll | visible | inherit). Try `visible` – Furious Duck May 12 '14 at 21:26
  • @AlexanderPetrovich Thank you very much!! Changing the style to `overflow: visible` solved the problem! I have trouble-shoot this problem for so many days. You help me a lot. Actually I copy the codes from this Stackoverflow post (http://stackoverflow.com/a/17684455/1460655). Not sure why `bbbco` use `overflow: none` in his codes. Anyway, please put your comment in the answer section so that I can mark it as accepted answer. Thanks :) – userpal May 14 '14 at 01:10
  • hi i am not sure how to do the same thing with selenium java (java script)can you please help me 1. how to change the button's aria-hidden="true" to aria-hidden="false",2.how to change the button's aria-hidden="true" to aria-hidden="false" – Rajnish Kumar Apr 29 '16 at 09:57

1 Answers1

1

Overflow takes only one of five values (overflow: auto | hidden | scroll | visible | inherit). Use visible

Furious Duck
  • 2,009
  • 1
  • 16
  • 18