gpt4 book ai didi

python - 异常 : Failed to start new browser session: Error while launching browser Selenium in Python

转载 作者:行者123 更新时间:2023-12-04 19:04:41 24 4
gpt4 key购买 nike

在 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 上运行。

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

最佳答案

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

export DISPLAY=:0

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

关于python - 异常 : Failed to start new browser session: Error while launching browser Selenium in Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3388714/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com