[英]Headless Edge Selenium Error: No browser is open
我正在嘗試讓 Edge 打開 Headless,但我不斷收到錯誤消息“沒有打開瀏覽器”。
這是 Python 代碼:
from msedge.selenium_tools import EdgeOptions
from msedge.selenium_tools import Edge
def function():
edge_options = EdgeOptions()
edge_options.use_chromium = True
edge_options.add_argument('headless')
edge_options.add_argument('disable-gpu')
driver = Edge(executable_path='C:/Users/ID75143/PycharmProjects/TestProject/venv/Scripts/MicrosoftWebDriver.exe', options=edge_options)
不管我在最后一行之后放了什么(我試過打開 URL 並最大化窗口),它說這是不可能的,因為“沒有打開瀏覽器”。 我試過在有頭模式下打開 Edge,然后它工作得很好,但不是無頭的。
有人知道該怎么做嗎?
根據您提供的代碼,我發現您使用的是 MicrosoftWebDriver。 它用於 Legacy Edge,有關詳細信息,請查看: 什么是 Microsoft Edge Legacy?
所以我必須再次確認,你使用的是正確版本的 Edge 瀏覽器和驅動程序嗎? 也許您應該在測試之前嘗試升級它們。
這是一個簡單的測試,它工作正常(版本 91.0.864.48 ):
from msedge.selenium_tools import Edge, EdgeOptions
options = EdgeOptions()
options.use_chromium = True
options.add_experimental_option("prefs", {
"download.default_directory": r"E:\Downloads" #change the route you need
})
options.add_argument("headless")
options.add_argument("disable-gpu")
driver = Edge(executable_path= #put your edgedriver here
r'C:\Users\Administrator\Desktop\msedgedriver.exe', options=options)
driver.get("https://www.seleniumhq.org/download/");
m = driver.find_element_by_link_text("32 bit Windows IE")
m.click()
而不是這個:
edge_options.add_argument('headless')
做這個:
edge_options.add_argument('--headless')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.