Selenium-解决使用Webdrive打开Firefox不含有插件的问题(python)
2013-03-27 14:31
886 查看
先看代码(只是一段代码):
上面这段代码运行的时候,selenium会打开一个新的,不含有任何插件和个人证书的firefox(等同于全新安装后第一次打开的那个firefox)。
但是有些时候,我们希望selenium打开的firefox要有插件或者有已经导入的个人证书,这种情况下,上面的代码就不起作用了。
这时候,我们就会用到firefoxprofile。
首先,介绍一下FirefoxProfile。
要了解Firefox profile请访问这里,它详细解绍了Firefox proflie。在Firefox里,如何管理Firefox profile 请访问这里。
既然已经了解过Firefox profile,那么来解决我上面提出的问题。
其实上面的问题很简单,就是使用selenium启动平时使用的Firefox,而不让系统去启动一个新的什么都没有的浏览器。
代码如下:
首先,我先定义我需要使用的profile的文件夹,然后创建一个profile,并且把profile的地址传给它,接着启动firefox的时候传入这个profile,这样,系统再打开的firefox就是我们平时使用的那个了。
from selenium import webdriver class Register(unittest.TestCase): def setUp(self): self.driver = webdriver.Firefox() self.driver.implicitly_wait(30) self.base_url = "https://www.example.com/" self.verificationErrors = [] self.accept_next_alert = true
上面这段代码运行的时候,selenium会打开一个新的,不含有任何插件和个人证书的firefox(等同于全新安装后第一次打开的那个firefox)。
但是有些时候,我们希望selenium打开的firefox要有插件或者有已经导入的个人证书,这种情况下,上面的代码就不起作用了。
这时候,我们就会用到firefoxprofile。
首先,介绍一下FirefoxProfile。
要了解Firefox profile请访问这里,它详细解绍了Firefox proflie。在Firefox里,如何管理Firefox profile 请访问这里。
既然已经了解过Firefox profile,那么来解决我上面提出的问题。
其实上面的问题很简单,就是使用selenium启动平时使用的Firefox,而不让系统去启动一个新的什么都没有的浏览器。
代码如下:
from selenium import webdriver class Register(unittest.TestCase): def setUp(self): self.profileDir = "\path\your\firefoxprofileDir" self.profile = webdriver.FirefoxProifle(self.profileDir) self.driver = webdriver.Firefox(self.profile) self.driver.implicitly_wait(30) self.base_url = "https://www.example.com/" self.verificationErrors = []
首先,我先定义我需要使用的profile的文件夹,然后创建一个profile,并且把profile的地址传给它,接着启动firefox的时候传入这个profile,这样,系统再打开的firefox就是我们平时使用的那个了。
相关文章推荐
- (selenium 小知识点)解决使用Webdrive打开Firefox不含有插件的问题(python)
- Python-Selenium2做Web自动化测试(6)-解决使用Webdrive打开Firefox不含有插件的问题
- Selenium+python-解决使用Webdrive打开Firefox不含有插件的问题
- 关于selenium 用Webdrive打开Firefox不含有插件的问题(python)
- 关于selenium 用Webdrive打开Firefox不含有插件的问题(python)
- 关于selenium 用Webdrive打开Firefox不含有插件的问题(python)
- 关于selenium 用Webdrive打开Firefox不含有插件的问题(python)
- Windows环境下使用python selenium 打开Firefox的问题总结
- python爬虫,selenium使用,Firefox-chrome-IE问题解决方法,selenium的基本操作
- 解决python selenium3启动不了firefox的问题
- Python Selenium 启动新版本Firefox失败问题解决方案
- 终于解决delicious插件在firefox升级至3.0后无法使用的问题
- python中使用selenium调用Firefox缺少geckodriver解决方法
- chrome/firefox插件ie tab,解决无法使用网银的问题
- 解决eclipse使用Python插件程序乱码问题
- selenium打开firefox打开为导入向导问题解决。
- 使用Python2.7操作Selenium2时只打开浏览器不load URL的解决方法
- Python-selenium-Firefox-chrome-IE问题解决方法
- Python-selenium-Firefox-chrome-IE问题解决方法
- Python+Selenium,使用WebDriver启动Firefox,但不打开URL