【问题标题】:Exception: Failed to start new browser session: Error while launching browser Selenium in Python异常:无法启动新的浏览器会话:在 Python 中启动浏览器 Selenium 时出错
【发布时间】:2011-03-24 06:07:29
【问题描述】:

在 Python 中运行基本 Selenium 测试脚本时出现以下错误:

======================================================================
ERROR: test_untitled (__main__.TestTesting)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "TestTesting.py", line 15, in setUp
    self.selenium.start()
  File "/usr/lib/python2.6/dist-packages/selenium.py", line 166, in start
    result = self.get_string("getNewBrowserSession", [self.browserStartCommand, self.browserURL])
  File "/usr/lib/python2.6/dist-packages/selenium.py", line 195, in get_string
    result = self.do_command(verb, args)
  File "/usr/lib/python2.6/dist-packages/selenium.py", line 191, in do_command
    raise Exception, data
Exception: Failed to start new browser session: Error while launching browser

----------------------------------------------------------------------
Ran 1 test in 20.427s

FAILED (errors=1)

代码是从 Selenium IDE、firefox 插件生成的,所以我不确定为什么它不起作用。我的猜测是某种配置不正确,但我不确定。这是我的代码:

from selenium import selenium

class TestTesting(unittest.TestCase):
    def setUp(self):
        self.verificationErrors = []
        self.selenium = selenium("localhost", 4444, "*firefox", "http://www.google.com/")
        self.selenium.start()

    def test_untitled(self):
        sel = self.selenium
        sel.open("/firefox?client=firefox-a&rls=org.mozilla:en-US:official")
        sel.type("sf", "test")
        sel.click("btnG")
        sel.wait_for_page_to_load("30000")

    def tearDown(self):
        self.selenium.stop()
        self.assertEqual([], self.verificationErrors)

if __name__ == "__main__":
    unittest.main()

服务器在 Ubuntu 上运行。

我怎样才能避免这个错误?

【问题讨论】:

    标签: python ubuntu selenium


    【解决方案1】:

    我要解决的问题是未设置 Firefox 的显示。所以我需要执行以下语句:

    export DISPLAY=:0
    

    就在我启动 Selenium 服务器之前。这解决了问题,但出现了一个新问题。

    【讨论】:

    • 我最初使用了该修复程序,它修复了我的部分问题。还有一个问题,可能是版本控制,会话作为 uuid 返回,但在 selenium.py 中将其转换为 long..这会产生问题。因此,出口 DISPLAY 和铸件固定的结合奏效了。
    【解决方案2】:

    这通常发生在另一个 Firefox 已打开时。即您正在使用特定的 FF 配置文件来测试应用程序。运行脚本时,关闭 FF。

    【讨论】:

    • 很遗憾,事实并非如此,即使 FF 完全没有运行也会发生这种情况。
    【解决方案3】:

    临时以 root 身份启动 selenium 服务器对我来说是个窍门:

    sudo java -jar selenium-server.jar
    

    【讨论】:

      猜你喜欢
      • 2010-11-27
      • 2023-03-10
      • 1970-01-01
      • 2015-04-08
      • 1970-01-01
      • 2012-04-21
      • 1970-01-01
      • 2023-03-05
      • 1970-01-01
      相关资源
      最近更新 更多