1

I'm trying to click a button with its class but it throws an ElementNotInteractableException. Here is the website HTML code

Here is the code I'm using

driver = webdriver.Chrome('chromedriver.exe', chrome_options=options)

driver.get('https://physionet.org/lightwave/?db=noneeg/1.0.0')

def get_spo2hr(subject):
    driver.find_element_by_xpath("//select[@name='record']/option[text()='"+subject+"']").click()
    driver.find_element_by_id('ui-id-3').click()
    driver.find_element_by_id('viewann').click()
    driver.find_element_by_id('viewsig').click()
    driver.find_element_by_id('lwform').click()
    driver.find_element_by_css_selector(".fwd").click()
    driver.save_screenshot('screenie.png')
    

get_spo2hr('Subject10_SpO2HR')

4
  • Can you share the website url? Commented Jun 21, 2020 at 17:11
  • physionet.org/lightwave/?db=noneeg/1.0.0 Please select Subject10_SpO2HR and change to tables tab to replicate the issue. Commented Jun 21, 2020 at 17:11
  • I should have read that line driver.get('https://physionet.org/lightwave/?db=noneeg/1.0.0') ... :) Commented Jun 21, 2020 at 17:14
  • @guest2341 This sounds like an X-Y problem. Instead of asking for help with your solution to the problem, edit your question and ask about the actual problem. What are you trying to do? Commented Jun 21, 2020 at 17:32

2 Answers 2

1

One thing is (as said in other answers) the unstable css selector prefer xpath

But the main thing is that the div is overlapping the a item at the dom rendering Just wait one second to wait until the dom loads:

import time
time.sleep(1)

Example code:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions

driver = webdriver.Chrome()
driver.get('https://physionet.org/lightwave/?db=noneeg/1.0.0')

def get_spo2hr(subject):
    driver.find_element_by_xpath("//select[@name='record']/option[text()='"+subject+"']").click()

    import time
    time.sleep(1)

    driver.find_element_by_id('ui-id-3').click()
    driver.find_element_by_id('viewann').click()
    driver.find_element_by_id('viewsig').click()
    driver.find_element_by_id('lwform').click()
    driver.find_element_by_xpath('/html/body/div[1]/main/div/div/div/form/div[3]/table/tbody/tr/td[2]/div/button[3]').click()
    driver.save_screenshot('screenie.png')

get_spo2hr('Subject10_SpO2HR')
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your answer. Its resolved now and I've learned a new thing :)
1

I always prefer getting elements using their xpath, of course, in suitable situations. With that being said, I modified your code to find the forward button using its xpath and it works.

Here is the modified code:

driver = webdriver.Chrome('chromedriver.exe', chrome_options=options)

driver.get('https://physionet.org/lightwave/?db=noneeg/1.0.0')

def get_spo2hr(subject):
    driver.find_element_by_xpath("//select[@name='record']/option[text()='" + subject + "']").click()
    driver.find_element_by_id('ui-id-3').click()
    driver.find_element_by_id('viewann').click()
    driver.find_element_by_id('viewsig').click()
    driver.find_element_by_id('lwform').click()
    driver.find_element_by_xpath('/html/body/div[1]/main/div/div/div/form/div[3]/table/tbody/tr/td[2]/div/button[3]').click()
    driver.save_screenshot('screenie.png')


get_spo2hr('Subject10_SpO2HR')

2 Comments

Thank you for your answer. I think as exception mentioned adding a timer for the dom to load is the best way to handle this so I'm considering his answer as resolved.
Normally you want to use WebDriverWait but in this case you are not waiting for an element to be generated by JavaScript, you are waiting for the browser to render the overlapping correctly.

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.