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?

2

1 Answer 1

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])
Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.