Python Selenium中的交换用户代理

Python Selenium中的交换用户代理,python,selenium,user-agent,Python,Selenium,User Agent,所以我想做的是将用户代理从桌面更改为iphone。我成功地做到了这一点,它的工作。然而,我有一个问题,为什么Firefox要推出两个窗口。我还想向社区寻求一些帮助和意见,说明我做错了什么 profile = webdriver.FirefoxProfile() profile.set_preference("general.useragent.override", "Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) App

所以我想做的是将用户代理从桌面更改为iphone。我成功地做到了这一点,它的工作。然而,我有一个问题,为什么Firefox要推出两个窗口。我还想向社区寻求一些帮助和意见,说明我做错了什么

    profile = webdriver.FirefoxProfile()
    profile.set_preference("general.useragent.override", "Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3")
    driver = webdriver.Firefox(profile)
    driver.get(config.host_url +'/sai')
    self.assertTrue(driver.find_element_by_css_selector('body > div.page-wrap > div.vertical-name-wrapper.underlined'))
    driver.quit()

这里的代码实际上会打开一个firefox浏览器两次(应该是吗?),我只想在用户代理已经更改的情况下打开一个浏览器窗口

您使用的是哪个selenium软件包版本?我无法复制此版本。在不使用断言的情况下运行此代码,并使用Google的主页作为URL,在我的系统上只会显示一个Firefox窗口(MacOS 10.8,在Python 2.7上安装了带有pip的stock selenium)。