【问题标题】:Error communicating with the remote browser It may have died与远程浏览器通信时出错它可能已经死了
【发布时间】:2016-12-15 04:38:07
【问题描述】:

我知道这个问题已经被问过很多次了,我已经检查过这些问题但找不到解决方案。上述错误并不常见,只是有时我得到它,所以我无法弄清楚它为什么会发生。执行以下行后代码

 driver.get(first_url)
    #here i open forst url the perform some operation    
    main_window =driver.current_window_handle
    driver.find_element_by_tag_name('body').send_keys(Keys.CONTROL + "t")
    #above line opens a new tab 
    # Put focus on current window which will, in fact, put focus on the current visible tab
    main_window_new =driver.current_window_handle
    driver.switch_to_window(main_window_new )
    time.sleep(1)
    driver.get(second_url)
    #opening new tab in the existing browser 
    time.sleep(2)
    json_str=driver.find_element_by_tag_name('body').text
    time.sleep(1)
    print json
    # Close current tab
    driver.find_element_by_tag_name('body').send_keys(Keys.CONTROL + 'w')

    # Put focus on current window which will be the window opener
    driver.switch_to_window(main_window)

我收到这个错误

消息:与远程浏览器通信时出错。它可能有 死了。构建信息:版本:'2.53.0',修订:'35ae25b',时间: '2016-03-15 17:00:58' 系统信息:主机:'BLR-CSM-1',ip: '172.17.1.34', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_101' 驱动程序信息: driver.version: RemoteWebDriver 功能 [{applicationCacheEnabled=true, 可旋转=false,handlesAlerts=true,databaseEnabled=true, 版本=35.0,平台=WINDOWS,nativeEvents=false, acceptSslCerts=true, webStorageEnabled=true, locationContextEnabled=true, browserName=firefox, 需要Screenshot=true,javascriptEnabled=true, cssSelectorsEnabled=true}] 会话 ID: d7ac8e9e-2c20-48c6-82fd-ce8eaec93b46 堆栈跟踪:('意外错误:', )

上述执行的 Selenium 服务器日志

13:21:08.048 INFO - Executing: [get current window handle])
13:21:08.058 INFO - Done: [get current window handle]
13:21:08.060 INFO - Executing: [find element: By.tagName: body])
13:21:08.068 INFO - Done: [find element: By.tagName: body]
13:21:08.071 INFO - Executing: [send keys: 603 [[FirefoxDriver: firefox on WINDO
WS (d52fe7cd-ee42-41f7-b065-ec1e853e1011)] -> tag name: body], [?, t]])
13:21:08.097 INFO - Done: [send keys: 603 [[FirefoxDriver: firefox on WINDOWS (d
52fe7cd-ee42-41f7-b065-ec1e853e1011)] -> tag name: body], [?, t]]
13:21:10.107 INFO - Executing: [get current window handle])
13:21:10.118 INFO - Done: [get current window handle]
13:21:10.122 INFO - Executing: [switch to window: {1d2e0152-8716-466e-bb62-d0a96
073fb3b}])
13:21:10.130 INFO - Done: [switch to window: {1d2e0152-8716-466e-bb62-d0a96073fb
3b}]
13:21:11.133 INFO - Executing: [get:https://myar.axyza.com/monitor/getStatsData?
graphTypeId=0])
13:21:12.173 INFO - Done: [get: https://myar.axyza.com/monitor/getStatsData?
graphTypeId=0])]
13:21:14.176 INFO - Executing: [find element: By.tagName: body])
13:21:14.185 INFO - Done: [find element: By.tagName: body]
13:21:14.188 INFO - Executing: [get text: 853 [[FirefoxDriver: firefox on WINDOW
S (d52fe7cd-ee42-41f7-b065-ec1e853e1011)] -> tag name: body]])
13:21:14.215 INFO - Done: [get text: 853 [[FirefoxDriver: firefox on WINDOWS (d5
2fe7cd-ee42-41f7-b065-ec1e853e1011)] -> tag name: body]]
13:21:15.221 INFO - Executing: [find element: By.tagName: body])
13:21:15.233 INFO - Done: [find element: By.tagName: body]
13:21:15.237 INFO - Executing: [send keys: 853 [[FirefoxDriver: firefox on WINDO
WS (d52fe7cd-ee42-41f7-b065-ec1e853e1011)] -> tag name: body], [?, w]])
13:21:15.367 INFO - Done: [send keys: 853 [[FirefoxDriver: firefox on WINDOWS (d
52fe7cd-ee42-41f7-b065-ec1e853e1011)] -> tag name: body], [?, w]]
13:21:17.371 INFO - Executing: [switch to window: {1d2e0152-8716-466e-bb62-d0a96
073fb3b}])
13:21:18.417 INFO - Executing: [close window])

感谢任何帮助。

【问题讨论】:

  • 对不起,错误在哪里?我只看到 INFO 日志
  • @Rudziankoŭ 请在上面找到
  • 您是否使用一些远程服务,例如soucelabsbrowserstack?测试运行多长时间?
  • 总是失败到同一行/代码?如果不是,您应该尝试其他 selenium 服务器版本,看看会发生什么,可能不是编码问题。
  • @Rudziankoŭ 没有远程服务,但我使用远程 webdriver。取决于输入。所以它可能长达一个小时

标签: python selenium selenium-webdriver


【解决方案1】:

因为如果只有一个标签页打开,下面的行将关闭您的浏览器。

# remove that line and run your code. You will not see this error again.
driver.find_element_by_tag_name('body').send_keys(Keys.CONTROL + 'w')

【讨论】:

  • 实际上我打开了两个标签。上面的代码 sn-p 用于在现有浏览器中打开新选项卡,我执行一些操作然后我切换回以前的现有选项卡
  • @AmarK 我运行你的脚本。它对我来说运行良好。你使用的是什么浏览器 ?以及什么版本的浏览器。还有你的硒版本是什么?
  • 对不起,我应该在问题描述的前面提到这一点。请参阅上面相应修改的代码
  • 通常它可以正常工作我并不总是随机看到该错误。我正在使用 firefox 35.0 和 selenium-server-standalone-2.53.0 和 python
  • 同一个脚本在不同输入的情况下多次运行会不会有问题?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-01-24
相关资源
最近更新 更多