mardi 27 octobre 2020

Cannot click on toggle with selenium because of ElementNotInteractableException

I am trying to click a toggle with Selenium Webdriver and Python but get the following exception:

 selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
                           (Session info: chrome=86.0.4240.111)

My HTML code

<div _ngcontent-c7="" class="form-group"><label _ngcontent-c7="" for="opened">Opened</label><div _ngcontent-c7="" class="toggle-switch"><input _ngcontent-c7="" id="opened" name="opened" type="checkbox" class="ng-untouched ng-pristine ng-valid"><label _ngcontent-c7="" for="opened"></label></div><span _ngcontent-c7="" class="form-control-helper">Toggle text description.</span></div>

I use the following selector and it is 100% unique:

.toggle-switch>label[for=opened]

What can be the problem? This is the Angular modal dialog. I tried many unique locators, both XPATH and CSS and I am sure this is not a locator problem. Did someone else had a similar problem?

My Python code:

    toggle = driver.find_element_by_css_selector(".toggle-switch>label[for=opened]")
    toggle.click()

Thanks.

Aucun commentaire:

Enregistrer un commentaire