1

I need to click on a button using selenium in python. This is what I have:

read_more_buttons = responses[0].find_elements_by_class_name("read-more")
            if len(read_more_buttons) > 0:
                read_more_buttons[0].click()

It works fine most of the time but sometimes there's an overlay on the bottom of the page, which can not be dismissed. Therefore I'd get this error:

[element] is not clickable at point (665.7333145141602,883.4666748046875) because another element <div class="raq-module js-raq-module"> obscures it

I tried to scroll down the page with this code right before calling click():

driver.execute_script("window.scrollTo(0, " + str(read_more_buttons[0].location["y"] + 120) + ")") 

However, I'm still receiving the same error. It seems like by calling .click() the element is scrolled to the very bottom of the page, which is right under the overlay. How can I move up the page and then click?

JeffC
  • 22,180
  • 5
  • 32
  • 55
bleepmeh
  • 967
  • 5
  • 17
  • 36
  • Are you working with a maximized window? – nilesh Apr 17 '18 at 02:45
  • Possible duplicate of [Element MyElement is not clickable at point (x, y)... Other element would receive the click](https://stackoverflow.com/questions/44724185/element-myelement-is-not-clickable-at-point-x-y-other-element-would-receiv) – undetected Selenium Apr 17 '18 at 10:39

1 Answers1

2

Those dang overlays!

Here, let's try and use JS to scroll into view and then click:

read_more_buttons = responses[0].find_elements_by_class_name("read-more")
if len(read_more_buttons) > 0:
    driver.execute_script("arguments[0].scrollIntoView(true);", read_more_buttons[0])
    driver.execute_script("arguments[0].click()", read_more_buttons[0])
PixelEinstein
  • 1,713
  • 1
  • 8
  • 17
  • If you are going to use JS to click the element, there's no point in scrolling. It will click it no matter where it is or what it's behind. It's only Selenium clicks that are blocked by other elements. Just know that by using JS to click an element, you are executing a click that no real user can do. If you are trying to simulate user behavior, scroll the page up slightly using JS and then Selenium click. – JeffC Apr 17 '18 at 02:32