【问题标题】:selenium can't open chrome browser on win7 in python?selenium 无法在 python 中的 win7 上打开 chrome 浏览器?
【发布时间】:2012-07-10 13:36:01
【问题描述】:

我正在尝试在 Windows 7 上的 python 中使用 selenium webdriver 打开 chrome 浏览器,但它挂起。下面是我使用的代码:

`

from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.proxy import *
import time
from pprint import pprint

chromeOps = webdriver.ChromeOptions()
print "after chrome opts", chromeOps
print dir(chromeOps)
pprint(chromeOps)
chromeOps.binary_location = "C:\\Users\\cvoicu\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe"

print "after binary loc"
browser = webdriver.Chrome("C:\\Python27\\chromedriver.exe", chrome_options=chromeOps)
print "after browser", browser
print dir(browser)
browser.get("http://www.google.com")

`

你能帮帮我吗?谢谢!

【问题讨论】:

  • 我看到你有一些调试代码。它在挂什么电话?您是否收到任何错误输出?
  • 没有任何错误。这里有挂之前的最后两行输出:after binary loc service url localhost:64960
  • 有时会到最后,但不会打开浏览器。

标签: python windows-7 selenium


【解决方案1】:

删除:

chromeOps = webdriver.ChromeOptions()
print "after chrome opts", chromeOps
print dir(chromeOps)
pprint(chromeOps)
chromeOps.binary_location = "C:\\Users\\cvoicu\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe"

print "after binary loc"

看看现在会发生什么。当我实例化 chrome 时,我只是设置了 chromedriver 的路径,它对我来说工作正常,也可能是在 Python27 中运行 chrome 驱动程序的烫发问题,尝试将它也移到其他地方

【讨论】:

  • 感谢您的回复。我尝试使用这些包含和 'browser = webdriver.Chrome("C:\\chromedriver.exe")',但没有任何反应。在任务管理器中,我可以看到它打开了 chromedriver,但没有打开 chrome 进程。你是在win7上运行的吗?
  • 另外我必须指定我在 64 位平台上有 win7。这会是chromedriver打开chrome浏览器的问题吗?
【解决方案2】:

我做了一些更改,去掉了 ChromeOpts,因为我的电脑上没有那个文件,它对我有用。确保将 chromedriver 添加到 PATH,您应该没问题。

from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.proxy import *
import time
from pprint import pprint
import os



chromedriver = "C:\Users\USER\AppData\Local\Google\Chrome\Application\chromedriver.exe"
os.environ["webdriver.chrome.driver"] = chromedriver

print "after binary loc"
browser = webdriver.Chrome(chromedriver)
print "after browser", browser
print dir(browser)
browser.get("http://www.google.com")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-10
    • 1970-01-01
    • 1970-01-01
    • 2018-02-01
    • 2013-11-07
    • 2017-01-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多