无法理解为什么“ selenium.common.exceptions.ElementNotInteractableException:消息:元素不可交互”

时间:2020-08-03 09:19:55

标签: python selenium selenium-chromedriver

"selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable"

这是我无缘无故得到的错误。我的意思是以前它曾经可以工作,但现在却没有。

在我的代码中有这个网站:https://www.tempinbox.xyz/ 我使用chromedriver打开它。 我想做的是从域的下拉菜单中选择(@ fitschool.be)。

并输入一些我存储为变量“ str(res)”的变量字符串

我的代码是:-

second_tab = webdriver.Chrome(options=options,)

    second_tab.get("https://www.tempinbox.xyz/")
    randombutton = second_tab.find_element_by_xpath("/html/body/main/div[1]/div/div[1]/div[2]/form[1]/input[2]") #for the email generation
    randombutton.send_keys(str(res))
    mainurl = second_tab.current_url

    selectoption1=second_tab.find_element_by_id("selected-domain").click()
    selectoption2=second_tab.find_element_by_css_selector(".domain-selector:nth-child(3)").click()

    clickfinal= second_tab.find_element_by_xpath("//input[@value='Create']").click()
    emailentry = str(res)+ "@fitschool.be"

    print ("your email is " + emailentry)

但这给了我错误。...

Traceback (most recent call last):
  File "C:\Users\BRS\Desktop\AccountChef\wattpad acc maker.py", line 45, in <module>
    selectoption2=second_tab.find_element_by_css_selector(".domain-selector:nth-child(3)").click()
  File "C:\Users\BRS\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webelement.py", line 80, in click
    self._execute(Command.CLICK_ELEMENT)
  File "C:\Users\BRS\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webelement.py", line 633, in _execute
    return self._parent.execute(command, params)
  File "C:\Users\BRS\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\Users\BRS\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
  (Session info: chrome=84.0.4147.105)

pls建议进行一些更改以及为什么会发生这种情况。谢谢:)

1 个答案:

答案 0 :(得分:1)

代替以下两行:

selectoption1=second_tab.find_element_by_id("selected-domain").click()
selectoption2=second_tab.find_element_by_css_selector(".domain-selector:nth-child(3)").click()

尝试使用.execute_script设置innerHTML值:

element = second_tab.find_element_by_id("selected-domain")
target = "@fitschool.be"
second_tab.execute_script("arguments[0].innerHTML = '{}';".format(target), element)