簡體   English   中英

使用 Selenium webdriver 模塊時無法打開 Firefox 瀏覽器

[英]Firefox browser does not open when using Selenium webdriver module

我期待下面的代碼將打開 Firefox 瀏覽器窗口,但它沒有,只打印我的日志句子。

誰能告訴我我做錯了什么?

from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
import time as tm

binary = r'C:\Users\asgar\AppData\Local\Mozilla Firefox\firefox.exe'
options = Options()
options.headless = True
options.binary = binary

cap = DesiredCapabilities().FIREFOX
cap["marionette"] = True #optional
driver = webdriver.Firefox(options=options, capabilities=cap, executable_path=r"C:\Users\asgar\PycharmProjects\firefoxselenium\geckodriver.exe")
driver.get("http://google.com/")
tm.sleep(10)

print ("Headless Firefox Initialized")
driver.quit()

嘗試這個; 只需將路徑更改為“geckodriver.exe”。

from selenium import webdriver
profile = webdriver.FirefoxProfile()
profile.accept_untrusted_certs = True
wd = webdriver.Firefox(executable_path="C:/your_path/geckodriver.exe", firefox_profile=profile)


url = "https://www.google.com/"
wd.get(url)

那樣有用嗎?

一方面,'options.headless = True' 看起來很可疑。 此外,瀏覽器右上角的 3 個水平欄(打開菜單)下可能有一個設置,用於控制新瀏覽器窗口打開的行為,因此請查看“打開菜單”中的復選框之一。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM