selenium.common.exceptions.ElementNotVisibleException:消息:无法使用 Selenium 交互的元素
selenium.common.exceptions.ElementNotVisibleException: Message: element not interactable using Selenium
我正在寻找一个有趣的程序,但我在使用 selenium 时遇到了一些问题,我
需要一些帮助...
这是程序(我删除了webdriver的目录,因为文件夹名称中包含其他人的名字)
from selenium import webdriver
import webbrowser
import time
def Pass_send_():
driver=webdriver.Chrome()
driver.get('chrome://flags/#password_export-enable')
ricerca=driver.find_element_by_id("search")
ricerca.send_keys('password export')
scorritore=driver.find_element_by_class_name('experiment-select')
scorritore.click()
Pass_send_()
所以目的很简单,它应该打开 windows,键入文本并单击按钮。一切正常,但点击无效,这是错误:
Traceback (most recent call last):
File "C:\Python34\internet22.py", line 18, in <module>
Pass_send_()
File "C:\Python34\internet22.py", line 14, in Pass_send_
scorritore.click()
File "C:\Python34\lib\site-
packages\selenium\webdriver\remote\webelement.py", line 80, in click
self._execute(Command.CLICK_ELEMENT)
File "C:\Python34\lib\site-
packages\selenium\webdriver\remote\webelement.py", line 633, in _execute
return self._parent.execute(command, params)
File "C:\Python34\lib\site-
packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Python34\lib\site-
packages\selenium\webdriver\remote\errorhandler.py", line 242, in
check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotVisibleException: Message: element not interactable
所以我不是专家,但它说:元素不可交互?这是什么意思,我该如何解决?非常感谢您的回复...
要将字符序列发送到网页搜索框,chrome://flags/#password_export-enable
您需要诱导WebDriverWait 可以使用以下解决方案:
代码块:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
options = Options()
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:\WebDrivers\chromedriver.exe')
driver.get('chrome://flags/#password_export-enable')
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input#search"))).send_keys("password export")
浏览器快照:
我正在寻找一个有趣的程序,但我在使用 selenium 时遇到了一些问题,我 需要一些帮助... 这是程序(我删除了webdriver的目录,因为文件夹名称中包含其他人的名字)
from selenium import webdriver
import webbrowser
import time
def Pass_send_():
driver=webdriver.Chrome()
driver.get('chrome://flags/#password_export-enable')
ricerca=driver.find_element_by_id("search")
ricerca.send_keys('password export')
scorritore=driver.find_element_by_class_name('experiment-select')
scorritore.click()
Pass_send_()
所以目的很简单,它应该打开 windows,键入文本并单击按钮。一切正常,但点击无效,这是错误:
Traceback (most recent call last):
File "C:\Python34\internet22.py", line 18, in <module>
Pass_send_()
File "C:\Python34\internet22.py", line 14, in Pass_send_
scorritore.click()
File "C:\Python34\lib\site-
packages\selenium\webdriver\remote\webelement.py", line 80, in click
self._execute(Command.CLICK_ELEMENT)
File "C:\Python34\lib\site-
packages\selenium\webdriver\remote\webelement.py", line 633, in _execute
return self._parent.execute(command, params)
File "C:\Python34\lib\site-
packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Python34\lib\site-
packages\selenium\webdriver\remote\errorhandler.py", line 242, in
check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotVisibleException: Message: element not interactable
所以我不是专家,但它说:元素不可交互?这是什么意思,我该如何解决?非常感谢您的回复...
要将字符序列发送到网页搜索框,chrome://flags/#password_export-enable
您需要诱导WebDriverWait 可以使用以下解决方案:
代码块:
from selenium import webdriver from selenium.webdriver.chrome.options import Options from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC options = Options() 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:\WebDrivers\chromedriver.exe') driver.get('chrome://flags/#password_export-enable') WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input#search"))).send_keys("password export")
浏览器快照: