重置为之前的文本框输入

重置为之前的文本框输入

本文介绍了提交表单后 Watir 文本框输入不持久(重置为之前的文本框输入)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在这个网站上做一些抓取:http://onthemap.ces.census.gov/

I'm doing a bit of scraping on this website: http://onthemap.ces.census.gov/

这是我的代码出现错误之前的设置:

Here's the setup to my code that precedes the error:

sample_address = "1600 Amphitheatre Pkwy, Mountain View, CA 94043"
b= Watir::Browser.new :chrome
b.goto "http://onthemap.ces.census.gov"
b.text_field(:id => "search_value").set sample_address
b.span(:id => "search_button_label").click
Watir::Wait.until { b.a(:text => "Geocoder Results").exists? }
address_selector = sample_address.split(" ")[0..1].join(" ")
b.a(:text => /#{address_selector}/).click
Watir::Wait.until { b.div(:class => "olPopup").exists? }
b.span(:text => Selection").click

所以现在我要尝试将 2 英里插入简单半径"框,其默认值为 0.25

So now I am about to try to plug in 2 miles into the "simple radius" box, whose DEFAULT VALUE is 0.25

b.text_field(:name => "simple_r").set 2.0

文本框按预期更改为 2.0.然后我尝试点击确认选择....

The text box changes to 2.0 as expected. Then I try to click to confirm the selection....

b.span(:text => "Confirm Selection").click

现在,simple_r"值突然恢复到以前的值 (0.25),我的脚本没用了.

Now, all of a sudden the "simple_r" value reverts back to its previous value (0.25) and my script is useless.

举例来说,如果我将 watir 对象连接到浏览器,然后继续在 Simple Ring radius 字段中手动输入100.0",然后拉起 watir 对象并再次运行此代码:

To illustrate, if I keep my watir object connected to the browser, and I then proceed to manually type in "100.0" into the Simple Ring radius field, THEN pull up the watir object and run this code again:

b.text_field(:name => "simple_r").set 2
b.span(:text => "Confirm Selection").click

simple_r"半径的值将恢复为 100.

The value for the "simple_r" radius will revert back to 100.

这是一个显示错误的小截屏视频.请注意,在截屏视频中,我没有单击任何按钮或手动输入任何文本.您需要将其切换到 720p 才能正常观看.http://youtu.be/gdDZWHwXduA

Here's a little screencast showing the error. Note in the screencast I'm not clicking any buttons or entering any text manually. You'll need to switch it to 720p to see properly. http://youtu.be/gdDZWHwXduA

推荐答案

似乎应该有 JavaScript 来触发简单半径字段的模糊.然而,它似乎并没有持续发射.手动触发 JavaScript 解决了这个问题:

It seems like there should be JavaScript that triggers on the blur of the simple radius field. However, it does not seem to be firing consistently. Manually firing the JavaScript addressed the issue:

b.text_field(:name => "simple_r").value = 2
b.text_field(:name => "simple_r").fire_event(:onblur)

请注意,我只能在 Firefox 中始终如一地重现该问题.我无法在 Chrome 中测试修复程序,因为问题从未发生过.

Note that I was only able to consistently reproduce the problem in Firefox. I was not able to test the fix in Chrome as the problem never occurred.

这篇关于提交表单后 Watir 文本框输入不持久(重置为之前的文本框输入)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 17:13