测试脚本中的非拉丁字母会导致“没有密钥翻译”。假设 unicode 输入...”

发布于 2024-12-01 11:10:42 字数 1442 浏览 1 评论 0原文

当我在 Windows7+Ruby1.9.2+watir-webdriver 上执行此测试脚本时:

# encoding: utf-8
require "rubygems"
require "watir-webdriver"
ie = Watir::Browser.new :ie
ie.goto "www.tilde.eu"
ie.select_list(:name => "tr-direction").select "Latvian-English"
ie.select_list(:name => "tr-direction").selected? "Latvian-English"
ie.text_field(:class => "tr-area").set "skolas dārzā aug divas priedes"
ie.element_by_xpath("/html/body/div[3]/div/div/div/section/div/div/div/form/table/tbody/tr/td[3]/input").click
Watir::Wait.until { ie.text.include? "About Tilde Machine Translation" }
puts ie.div(:class => "translate_text_result").text

脚本执行得很好,就像在 Firefox 中一样,但是 IE9 在尝试在文本字段中设置“ā”字母时崩溃,并且 CMD 显示以下内容:

No translation for key. Assuming unicode input: 257
Timeout awaiting keypress: 82
Key up failed: 1400
Key down failed: 1400
Timeout awaiting keypress: 90
Key up failed: 1400
No translation for key. Assuming unicode input: 257
Key down failed: 1400

脚本在 Chrome 中完全执行,但仍然显示 CMD 中的一些警告:

Started ChromeDriver
port=52409
version=14.0.836.0
[0825/095000:WARNING:webdriver_key_converter.cc(271)] No translation for key code. Code point: 257
[0825/095000:WARNING:webdriver_key_converter.cc(271)] No translation for key code. Code point: 257

除了 #encoding: utf-8 之外,我还需要指定其他内容才能在 IE 和 Chrome 中正常工作吗?

我建议在您的计算机上执行上述脚本,以确定这是否是常见问题或只是我的配置中的问题。

When I execute on Windows7+Ruby1.9.2+watir-webdriver this test script:

# encoding: utf-8
require "rubygems"
require "watir-webdriver"
ie = Watir::Browser.new :ie
ie.goto "www.tilde.eu"
ie.select_list(:name => "tr-direction").select "Latvian-English"
ie.select_list(:name => "tr-direction").selected? "Latvian-English"
ie.text_field(:class => "tr-area").set "skolas dārzā aug divas priedes"
ie.element_by_xpath("/html/body/div[3]/div/div/div/section/div/div/div/form/table/tbody/tr/td[3]/input").click
Watir::Wait.until { ie.text.include? "About Tilde Machine Translation" }
puts ie.div(:class => "translate_text_result").text

Script executes fine as it is in Firefox, but IE9 crashes when trying to set "ā" letter in text field and CMD shows following:

No translation for key. Assuming unicode input: 257
Timeout awaiting keypress: 82
Key up failed: 1400
Key down failed: 1400
Timeout awaiting keypress: 90
Key up failed: 1400
No translation for key. Assuming unicode input: 257
Key down failed: 1400

Script executes completely in Chrome, but still some warning in CMD are shown:

Started ChromeDriver
port=52409
version=14.0.836.0
[0825/095000:WARNING:webdriver_key_converter.cc(271)] No translation for key code. Code point: 257
[0825/095000:WARNING:webdriver_key_converter.cc(271)] No translation for key code. Code point: 257

Do I need to specify anything else apart from # encoding: utf-8 for it to work correctly in IE and Chrome?

I suggest to excecute above script on your computer to determine if this is common issue or just something in my configuration.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

野生奥特曼 2024-12-08 11:10:42

This is a known bug in the IE driver, which you can follow here. The warnings in Chrome are harmless, though they probably shouldn't be printed by default.

兮颜 2024-12-08 11:10:42

我发现只有在设置了非 Windows 键盘布局时才会出现此问题。
如果在脚本执行机器上设置了任何标准 Windows 布局,例如“Latvian(QWERTY)”,则 IE 不会再崩溃,只会输出类似于 Chrome 的警告。

修复 IE 驱动程序错误之前的临时破解可能是在执行测试套件之前设置标准 Windows 键盘布局,并在执行后恢复到之前的布局。

如何使用 ruby​​ 获取 Windows 上的键盘布局?< /a> - 寻找灵感。

I've discovered that issue is actual only if non-windows keyboard layout is set.
If any of standard windows layouts is set e.g. "Latvian(QWERTY)" on script execution machine, IE doesn't crash anymore just outputs warnings similar to Chrome.

Temporary hack until IE driver bug is fixed could be to set standard windows keyboard layout before execution of test suite and to revert to previous one after execution.

How to get the keyboard layout on windows with ruby? - for inspiration.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文