Selenium打开浏览器,但不加载页面 [英] Selenium opens browser but doesn't load page

查看:1560
本文介绍了Selenium打开浏览器,但不加载页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是从以前发布的一个扩展,我做了这里我无法去工作,但我现在得到一个新的错误后更新Selenium。



我使用Python 3.5,Windows 8.1,Selenium 3.0.1



我知道代码的工作原理是因为它在我的MAC上工作,但是当我把它带到我上面描述的工作计算机时,唯一发生的事情是浏览器将打开,它不会加载任何东西,甚至没有一个主页。

从我能找到的所有搜索我下载geckodriver,重命名为wires.exe,我添加目录到系统路径。





我完全不知道该怎么做才能使其工作。这里是代码即时通讯:

  from selenium import webdriver 

driver = webdriver.Firefox()

driver.get('https://www.google.com')

下面是我得到的错误:

解决方案

我没有将geckodriver添加到PATH(它位于与Python脚本相同的目录中) selenium更新到3.0.1使用这段代码来启动selenium会话:

$ $ p $ $ $ $ $ gecko = os.path.normpath(os.path。加入(os.path.dirname(__ file__),'geckodriver'))
binary = FirefoxBinary(r'C:\Program Files(x86)\Mozilla Firefox\firefox.exe')
driver = webdriver.Firefox(firefox_binary = binary,executable_path = gecko +'。exe')

另外:你需要更新geckodriver到最新版本0.11.1。


this is an extension from a previous post I made Here which I could not get to work but I am now getting a new error after updating Selenium.

I am using Python 3.5, Windows 8.1, Selenium 3.0.1

I know the code works because it works on my MAC, but when I bring it over to my work computer which is described above, the only thing that happens is the browser will open but it wont load anything, not even a homepage.

From everything I could find on search I downloaded the geckodriver, renamed it to wires.exe and I added the directory to the system PATH.

I am completely lost on what to do to get this to work. Here is the code im using:

from selenium import webdriver

driver = webdriver.Firefox()

driver.get('https://www.google.com')

Here are the errors I am getting:

解决方案

I did not add geckodriver to PATH (it is located in the same directory as Python script), and after selenium update to 3.0.1 use this code to start selenium session:

gecko = os.path.normpath(os.path.join(os.path.dirname(__file__), 'geckodriver'))
binary = FirefoxBinary(r'C:\Program Files (x86)\Mozilla Firefox\firefox.exe')
driver = webdriver.Firefox(firefox_binary=binary, executable_path=gecko+'.exe')

Additionally: you need update geckodriver to the latest version 0.11.1.

这篇关于Selenium打开浏览器,但不加载页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆