selenium.common.exceptions.ElementNotInteractableException:消息:使用 Selenium Python 单击元素时元素不可交互 [英] selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable when clicking on an element using Selenium Python

查看:164
本文介绍了selenium.common.exceptions.ElementNotInteractableException:消息:使用 Selenium Python 单击元素时元素不可交互的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有人问过这个问题,但我需要一些解决此错误的方法:

I understand this question has been asked but I need some solution for this error:

 Traceback (most recent call last):
 File "goeventz_automation.py", line 405, in <module>
if login(driver) is not None:
File "goeventz_automation.py", line 149, in login
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[@track-element='header-login']"))).click()
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/support/wait.py", line 80, in until
raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:

这是出现错误的代码:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import TimeoutException
import urllib.request as request
import urllib.error as error
from PIL import Image
from selenium.webdriver.chrome.options import Options
import datetime as dt
import time
from common_file import *
from login_credentials import *

def login(driver):
global _email, _password
if waiter(driver, "//a[@track-element='header-login']") is not None:
    #login = driver.find_element_by_xpath("//a[@track-element='header-login']")
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[@track-element='header-login']"))).click()
    #login.click()
    if waiter(driver,"//input[@id='user_email']") is not None:
        email = driver.find_element_by_xpath("//input[@id='user_email']")
        password = driver.find_element_by_xpath("//input[@id='password']")
        email.send_keys(_email)
        password.send_keys(_password)
        driver.find_element_by_xpath("//button[@track-element='click-for-login']").click()
        return driver
    else:
        print("There was an error in selecting the email input field. It may be the page has not loaded properly.")
        return None
else:
    print("There was an error in selecting the header-login attribute on the page.")
    return None

if __name__ == '__main__':
    chrome_options = Options()
    chrome_options.add_argument('--headless')
    chrome_options.add_argument('--no-sandbox')
    chrome_options.add_argument('--disable-dev-shm-usage')

    driver = webdriver.Chrome('/usr/bin/chromium/chromedriver',chrome_options=chrome_options)
    #d.get('https://www.google.nl/')
    #driver = webdriver.Chrome()
    driver.maximize_window()
    driver.get('https://www.goeventz.com/')
    if login(driver) is not None:
        print(create_event(driver))

我认为 Keys.ENTER 存在一些问题,但我不知道如何解决这个问题.我已经尝试了所有可能的解决方案........

I think there is some problem with Keys.ENTER, but I don't know how to solve this. I have tried every possible solution.............

推荐答案

此错误信息...

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

...意味着当您尝试对其调用 click() 时,所需元素不是可交互的.

...implies that the desired element was not interactable when you tried to invoke click() on it.

几个事实:

  • 当您始终在 最大化 模式下初始化 Chrome 浏览器时.
  • 您可以禁用扩展.
  • 您还需要禁用信息栏.
  • When you initialize the Chrome browser always in maximized mode.
  • You can disable-extensions.
  • You need to disable-infobars as well.

我使用了与您构建的相同的 xpath,您可以使用以下解决方案:

I have used the same xpath which you have constructed and you can use the following solution:

  • 代码块:

  • Code Block:

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By

options = webdriver.ChromeOptions()
options.add_argument("start-maximized");
options.add_argument("disable-infobars")
options.add_argument("--disable-extensions")
driver = webdriver.Chrome(chrome_options=options, executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')
driver.get("https://www.goeventz.com/")
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//a[@track-element='header-login']"))).click()

  • 浏览器快照:

  • Browser Snapshot:

    这篇关于selenium.common.exceptions.ElementNotInteractableException:消息:使用 Selenium Python 单击元素时元素不可交互的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆