Home > Enterprise >  Handling drop down with selenium , X path method not working?
Handling drop down with selenium , X path method not working?

Time:01-06

I am trying to click Python present in the testlang dropdown list with id of select as lang1 but I am getting error here as selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable: Element is not currently visible and may not be manipulated , xpath I am trying is //select[@id ="lang1"]/option[@value="3"]

website https://pynishant.github.io/dropdown-selenium-python-select.html

This is my code:

    self.driver.get(
        'https://pynishant.github.io/dropdown-selenium-python-select.html')
    sleep(1)
    self.driver.maximize_window()
    sleep(2)
    wait = WebDriverWait(self.driver, 20)

    select = wait.until(EC.presence_of_element_located((By.CLASS_NAME, "custom-select")))
    print(select)
    drop = self.driver.find_element(By.CLASS_NAME,"custom-select")
    drop.click()
    sleep(2)
    sel = self.driver.find_element(By.XPATH,'//select[@id ="lang1"]/option[@value="3"]')
    sel.click()
    sleep(2)

CodePudding user response:

The Problem:

What you are trying to click is not displayed/present inside the DOM, it's the list which has all the elements present, but they are not processed on the DOM.

Hence you get the error: ElementNotInteractableException

The Solution: You should try to click what's present inside the DOM.

you can try the below code and it should work fine.

sel = self.driver.find_element(By.XPATH, '//*[@]/div[3]')
  • Related