简体   繁体   English

异常:无法启动新的浏览器会话:在Python中启动浏览器Selenium时出错

[英]Exception: Failed to start new browser session: Error while launching browser Selenium in Python

I am getting the following errors when running a basic Selenium test script in Python: 在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)

The code was generated from the Selenium IDE, the firefox plug in, so I am not sure why it doesn't work. 该代码是从Selenium IDE(firefox插件)生成的,因此我不确定为什么它不起作用。 My guess is some sort of configuration is incorrect, but I am not sure. 我的猜测是某种配置不正确,但是我不确定。 Here is my code: 这是我的代码:

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()

The server is running on Ubuntu. 该服务器正在Ubuntu上运行。

How can I avoid this error? 我怎样才能避免这个错误?

The fix that I got to work was that the display for firefox was not set. 我要解决的问题是未设置firefox的显示。 So I needed to execute the following statement: 所以我需要执行以下语句:

export DISPLAY=:0

right before I started the Selenium server. 在我启动Selenium服务器之前。 This solve the issue, but a new one has arisen. 解决了这个问题,但是出现了一个新问题。

This normally happens when another firefox is already opened. 当已经打开另一个Firefox时,通常会发生这种情况。 ie You are using specific FF profile to tet application. 即您正在使用特定的FF配置文件来测试应用程序。 When you run the script, close FF. 运行脚本时,关闭FF。

以root身份临时启动Selenium服务器对我有用:

sudo java -jar selenium-server.jar

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM