pythonselenium-webdriverselenium-chromedriver

Selenium python how I preform a click on toggle button


I am trying to click in call loop toggle with Selenium with the WebDriver on Python.

the html code:

enter image description here

this is the button:

enter image description here

I have tried few options:

button_element = driver.find_element_by_class_name("iPhoneCheckContainer")
button_element.click()

the filed message:

Traceback (most recent call last):
  File "C:\Users\kosti\PycharmProjects\test1\main.py", line 50, in <module>
    element = driver.find_element_by_xpath("//input[@id='on_off_on']").click()
  File "C:\Users\kosti\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webelement.py", line 80, in click
    self._execute(Command.CLICK_ELEMENT)
  File "C:\Users\kosti\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webelement.py", line 633, in _execute
    return self._parent.execute(command, params)
  File "C:\Users\kosti\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\Users\kosti\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <input type="checkbox" id="on_off_on" value="1" name="AllowReset" checked=""> is not clickable at point (171, 261). Other element would receive the click: <div class="iPhoneCheckHandle" style="width: 30px; left: 30px;">...</div>
  (Session info: chrome=88.0.4324.150)

Solution

  • from selenium.webdriver.common.by import By
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    
    elem=WebDriverWait(driver,5000).until(EC.visibility_of_element_located(
        (By.XPATH, "//input[@id='on_off_on']")))
    
    driver.execute_script("arguments[0].scrollIntoView();",elem)
    
    element.click()
    

    Try using webdriver wait