Ruby-Selenium WebDriver 3.142.6:由于“Selenium::WebDriver::Error::UnknownCommandError:"而无法上传文件 [英] Ruby-Selenium WebDriver 3.142.6: Unable to upload file due to "Selenium::WebDriver::Error::UnknownCommandError:"

查看:54
本文介绍了Ruby-Selenium WebDriver 3.142.6:由于“Selenium::WebDriver::Error::UnknownCommandError:"而无法上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无法在 Ruby 中使用 selenium-webdriver (3.142.6) gem 上传文件

技术栈:

<块引用>

selenium-webdriver (3.142.6)

Chrome 版本:77

Chrome 驱动程序:77

错误信息:

Selenium::WebDriver::Error::UnknownCommandError:未知命令:未知命令:session/xxxsession_idXXX/se/file回溯:序数 0 [0x00FDEB13+1501971]序号0 [0x00F5F6D1+980689]序号0 [0x00EE765F+489055]序号 0 [0x00E9618E+156046]序数 0 [0x00E95FF4+155636]序号0 [0x00E7220E+8718]序号 0 [0x00E72626+9766]序号0 [0x00E72C10+11280]序数 0 [0x00F78F37+1085239]GetHandleVerifier [0x0107D7ED+503293]GetHandleVerifier [0x0107D580+502672]GetHandleVerifier [0x010846AC+531644]GetHandleVerifier [0x0107DFFA+505354]序数 0 [0x00F70606+1050118]序号 0 [0x00F7047F+1049727]序数 0 [0x00E7204B+8267]序数 0 [0x00E71D7C+7548]GetHandleVerifier [0x013CD83C+3976780]BaseThreadInitThunk [0x755738F4+36]RtlUnicodeStringToInteger [0x77375E13+595]RtlUnicodeStringToInteger [0x77375DDE+542]

这个版本的 gem 好像上传失败了.

用于上传文件的代码(watir with cheezy)

@browser.file_field(xpath: "//*[contains(text(), 'Upload')]/input[@type='file']").set(complete_path_to_file)

解决方案

根本原因: w3c 浏览器能力状态

说明:w3c:true selenium webdriver 抛出此错误时.这可能是因为 Selenium 3 并不完全支持 w3c 实现.

解决方案 1:如果您没有任何基于 w3c 功能的依赖项,那么简单的解决方案是制作 w3c:false.

解决方案 2:如果解决方案 1 不起作用,那么您必须更新 selenium-webdriver-3.142.6\lib\selenium\webdriver\remote\w3c\commands.rb 文件.检查下面的行,然后更新它.

<块引用>

upload_file: [:post, 'session/:session_id/se/file']

将此行更新为

upload_file: [:post, 'session/:session_id/file']

结论:在 Selenium 4 推出之前更倾向于使用解决方案 1.如果您使用解决方案 2,则当您尝试在未推送此更改的机器上运行它们时,测试可能会失败/文件可能会被 bundle install 设置回原位.

你可以用overright方法来解决,但我个人觉得太多了.

将解决方案发布到SeleniumHQ,确认后提交Pull Request给SeleniumHQ.这样您就不会在更高版本的 Selenium Ruby WebDriver 中遇到这个问题.

Unable to upload the file using selenium-webdriver (3.142.6) gem in Ruby

Tech stack:

selenium-webdriver (3.142.6)

Chrome Version : 77

Chrome driver: 77

Error Message:

Selenium::WebDriver::Error::UnknownCommandError: unknown command: unknown command: session/xxxsession_idXXX/se/file
Backtrace:
       Ordinal0 [0x00FDEB13+1501971]
       Ordinal0 [0x00F5F6D1+980689]
        Ordinal0 [0x00EE765F+489055]
        Ordinal0 [0x00E9618E+156046]
        Ordinal0 [0x00E95FF4+155636]
        Ordinal0 [0x00E7220E+8718]
  Ordinal0 [0x00E72626+9766]
  Ordinal0 [0x00E72C10+11280]
 Ordinal0 [0x00F78F37+1085239]
       GetHandleVerifier [0x0107D7ED+503293]
       GetHandleVerifier [0x0107D580+502672]
       GetHandleVerifier [0x010846AC+531644]
       GetHandleVerifier [0x0107DFFA+505354]
       Ordinal0 [0x00F70606+1050118]
       Ordinal0 [0x00F7047F+1049727]
       Ordinal0 [0x00E7204B+8267]
  Ordinal0 [0x00E71D7C+7548]
  GetHandleVerifier [0x013CD83C+3976780]
      BaseThreadInitThunk [0x755738F4+36]
 RtlUnicodeStringToInteger [0x77375E13+595]
  RtlUnicodeStringToInteger [0x77375DDE+542]

Seems to be the upload is broken with this version of gem.

Code used to upload the file (watir with cheezy)

@browser.file_field(xpath: "//*[contains(text(), 'Upload')]/input[@type='file']").set(complete_path_to_file)

解决方案

Root Cause: w3c browser capability status

Explanation: When w3c:true selenium webdriver is throwing this error. This might be because of Selenium 3 is not at fully supporting w3c implementation.

Solution1: Simple solution would be making w3c:false if you don't have any dependencies based of the w3c capability.

Solution2: If solution 1 doesn't work then you have to update the selenium-webdriver-3.142.6\lib\selenium\webdriver\remote\w3c\commands.rb file. check for below line and then update it.

upload_file: [:post, 'session/:session_id/se/file']

Updating this line to

upload_file: [:post, 'session/:session_id/file']

Conclusion: Would prefer solution 1 until Selenium 4 is rolled out. If you go with solution 2 there is possibility of test failure when you try to run them on the machine where this change is not pushed/ the file might be set back with bundle install.

You can use the method overright approach to go with solution but personally I feel it's too much.

Posted the solution to SeleniumHQ, will submit Pull Request to SeleniumHQ once got confirmation. So that you don't face this issue in later version of Selenium Ruby WebDriver.

这篇关于Ruby-Selenium WebDriver 3.142.6:由于“Selenium::WebDriver::Error::UnknownCommandError:"而无法上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆