python webDriver怎么驱动不在默认安装路径的firefox

xingfuxiangyi 2014-08-27 11:55:27
本人初学python+selenium,由于我的firefox不在默认安装路径,所以打开比较麻烦一些,以下是我的代码执行的时候老是报错 :
import os
from selenium import webdriver
from selenium.webdriver.common.keys import Keys

firefoxdriver = "D:\Program Files\Mozilla Firefox\firefox.exe"
os.environ["webdriver.firefox.driver"] = firefoxdriver
print "1"
driver = webdriver.Firefox(firefoxdriver)
print "2"
driver.get("http://www.python.org")
print "3"
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.send_key("selenium")
elem.send_key(Keys.RETURN)
assert "Google" in driver.title
driver.close()
driver.quit()
以下是错误信息:

望有大神能够给我指教!谢谢!
...全文
2247 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
xingfuxiangyi 2014-09-01
  • 打赏
  • 举报
回复
引用 5 楼 u013544265 的回复:

from selenium import webdriver
firefoxdriver = webdriver.Firefox()
firefoxdriver.get("http://www.python.org")
这样就可以了呀,他会自己找你的firefox driver
我把firefox重装到默认路径,结果运行上面的代码还是报错,以下是报错代码: File "seleniumTest.py", line 3, in <module> browser = webdriver.Firefox() File "D:\Program Files\Python27\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 59, in __init__ self.binary, timeout), File "D:\Program Files\Python27\lib\site-packages\selenium\webdriver\firefox\extension_connection.py", line 47, in __i nit__ self.binary.launch_browser(self.profile) File "D:\Program Files\Python27\lib\site-packages\selenium\webdriver\firefox\firefox_binary.py", line 61, in launch_br owser self._wait_until_connectable() File "D:\Program Files\Python27\lib\site-packages\selenium\webdriver\firefox\firefox_binary.py", line 105, in _wait_un til_connectable self.profile.path, self._get_firefox_output())) selenium.common.exceptions.WebDriverException: Message: 'Can\'t load the profile. Profile Dir: c:\\users\\rongina\\appda ta\\local\\temp\\tmpfgpclg Firefox output: 1409551931269\taddons.manager\tDEBUG\tLoaded provider scope for resource://gr e/modules/addons/XPIProvider.jsm: ["XPIProvider"]\r\n1409551931272\taddons.manager\tDEBUG\tLoaded provider scope for res ource://gre/modules/LightweightThemeManager.jsm: ["LightweightThemeManager"]\r\n1409551931275\taddons.xpi\tDEBUG\tstartu p\r\n1409551931275\taddons.xpi\tDEBUG\tSkipping unavailable install location app-system-local\r\n1409551931276\taddons.x pi\tDEBUG\tSkipping unavailable install location app-system-share\r\n1409551931316\taddons.xpi\tDEBUG\tcheckForChanges\r \n'
  • 打赏
  • 举报
回复
python引入文件好像好分别引用,不能一起。
The_Third_Wave 2014-08-27
  • 打赏
  • 举报
回复
只能说楼主去看看文档吧,The first argument to webdriver.Firefox is supposed to be a webdriver.FirefoxProfile not a string.参数错误。
jeky_zhang2013 2014-08-27
  • 打赏
  • 举报
回复
从报错中找行数,在分析哪个参数错误,是类型方面,查下方法的参数类型
xingfuxiangyi 2014-08-27
  • 打赏
  • 举报
回复
引用 1 楼 u013171165 的回复:
只能说楼主去看看文档吧,The first argument to webdriver.Firefox is supposed to be a webdriver.FirefoxProfile not a string.参数错误。
还是有些不明白,哪里的文档呢? 上面代码哪个地方错了呢?

37,719

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧