与远程浏览器通信时出错可能已经死亡

时间:2016-08-09 08:22:14

标签: python selenium selenium-webdriver

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

 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,   rotating = false,handlesAlerts = true,databaseEnabled = true,   version = 35.0,platform = WINDOWS,nativeEvents = false,   acceptSslCerts = true,webStorageEnabled = true,   locationContextEnabled = true,browserName = firefox,   takesScreenshot = true,javascriptEnabled = true,   cssSelectorsEnabled = true}]会话ID:   d7ac8e9e-2c20-48c6-82fd-ce8eaec93b46 Stacktrace :('意外错误:',   )

以上执行的Selenium Server日志

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

感谢任何帮助。

1 个答案:

答案 0 :(得分: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')