使用Selenium Webdriver模块时,Firefox浏览器无法打开

问题描述 投票:1回答:1

我期望下面的代码将打开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()
python selenium selenium-webdriver webdriver geckodriver
1个回答
0
投票

尝试一下;只需将路径更改为'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个水平栏(“打开菜单”)下可能会有一个设置,用于控制新浏览器窗口打开的行为,因此请查看“打开菜单”中的复选框之一。 >

© www.soinside.com 2019 - 2024. All rights reserved.