問題描述
我正在尋找一個有趣的程序,但我對 selenium 有一些問題,我需要一些幫助...這是程序(我刪除了webdriver的目錄,因為文件夾的名稱包含其他人的名字)
I am searching to do a program for fun but i have some problems with selenium and i need some help... This is the programm (i deleted the directory of webdriver because the folder's name contain the name of an other person)
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_()
所以它的目的很簡單,它應該打開一個窗口,輸入一個文本并單擊一個按鈕.一切正常,但點擊沒有,這是錯誤:
And so the purpose it's easy, it should open a windows, type a text and click a button. everything works but the click doesn't and this is the error:
Traceback (most recent call last):
File "C:Python34internet22.py", line 18, in <module>
Pass_send_()
File "C:Python34internet22.py", line 14, in Pass_send_
scorritore.click()
File "C:Python34libsite-
packagesseleniumwebdriver
emotewebelement.py", line 80, in click
self._execute(Command.CLICK_ELEMENT)
File "C:Python34libsite-
packagesseleniumwebdriver
emotewebelement.py", line 633, in _execute
return self._parent.execute(command, params)
File "C:Python34libsite-
packagesseleniumwebdriver
emotewebdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:Python34libsite-
packagesseleniumwebdriver
emoteerrorhandler.py", line 242, in
check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotVisibleException: Message: element not interactable
所以我不是專家,但它說:元素不可交互?這是什么意思,我該如何解決?非常感謝您的回復...
So i am not an expert but it says: element not intercatable? what does it mean and how can i fix it? i would really appreciate a reply...
推薦答案
發送一個字符序列到網頁中的搜索框 chrome://flags/#password_export-enable
需要誘導WebDriverWait,可以使用如下解決方案:
To send a character sequence to the search box within the webpage chrome://flags/#password_export-enable
you need to induce WebDriverWait and you can use the following solution:
代碼塊:
Code Block:
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:WebDriverschromedriver.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")
瀏覽器快照:
Browser Snapshot:
這篇關于selenium.common.exceptions.ElementNotVisibleException:消息:元素無法使用 Selenium 進行交互的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!