selenium是怎么启动firefox

如题所述

from selenium import webdriver   class Register(unittest.TestCase):   def setUp(self):   self.driver = webdriver.Firefox()   self.driver.implicitly_wait(30)   self.base_url = ""   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.FirefoxProfile(self.profileDir)   self.driver = webdriver.Firefox(self.profile)   self.driver.implicitly_wait(30)   self.base_url = ""   self.verificationErrors = []   首先,我先定义我需要使用的profile的文件夹,然后创建一个profile,并且把profile的地址传给它,接着启动firefox的时候传入这个profile,这样,系统再打开的firefox就是我们平时使用的那个了。  
温馨提示:答案为网友推荐,仅供参考
第1个回答  2016-08-13
  您好,很高兴为您解答:
  from selenium import webdriver

  class Register(unittest.TestCase):
  def setUp(self):
  self.driver = webdriver.Firefox()
  self.driver.implicitly_wait(30)
  self.base_url = ""
  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.FirefoxProfile(self.profileDir)
  self.driver = webdriver.Firefox(self.profile)
  self.driver.implicitly_wait(30)
  self.base_url = ""
  self.verificationErrors = []

  首先,我先定义我需要使用的profile的文件夹,然后创建一个profile,并且把profile的地址传给它,接着启动firefox的时候传入这个profile,这样,系统再打开的firefox就是我们平时使用的那个了

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网