Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用Selenium webdriver模块时,Firefox浏览器未打开_Python_Selenium_Selenium Webdriver_Webdriver_Geckodriver - Fatal编程技术网

Python 使用Selenium webdriver模块时,Firefox浏览器未打开

Python 使用Selenium webdriver模块时,Firefox浏览器未打开,python,selenium,selenium-webdriver,webdriver,geckodriver,Python,Selenium,Selenium Webdriver,Webdriver,Geckodriver,我希望下面的代码会打开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:\

我希望下面的代码会打开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个水平条(打开菜单)下可能有一个设置,用于控制新浏览器窗口打开的行为,因此请查看“打开菜单”中的一个复选框。

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