填写文本表单 - 字符串太小?
我目前必须做一项工作,必须将网站的代码复制到文本字段中。
我正在使用 watir 进行浏览器处理。据我所知,我只能使用 set
函数填充该字段,这意味着我必须执行类似的操作,
browser.text_field(:id => "text").set sitetext
将 sitetext
作为我要访问的网站的代码正在复制进去。 我之前已使用以下代码将文件中的代码加载到数组中,然后将其推入字符串中(可能不是最佳选择,但现在对我来说最简单)。
contentArray=Array.new
inputFile=File.open("my-site.html")
inputFile.each{|line| contentArray<<line}
inputFile.close
现在,当我执行第一个命令来填充文本字段时,它会慢慢地输入所有字母(有没有简单的方法可以加快速度?),但在 692 个字符之后,它会停在句子的中间。 [我粘贴了在 charcounter.com 中输入的文本,这就是我知道这个数字的方式。]
问题出在哪里? ruby 是否出于某种原因限制了我的字符串大小?我能以某种方式解除这个障碍吗?
还有其他方法来填充文本字段吗?
I currently have to do a job where I have to copy the code of a website into a textfield.
I'm using watir to do the browser handling. As far as I know, I can only fill the field using the set
function, which means that I have to do something like
browser.text_field(:id => "text").set sitetext
With sitetext
being the code of the website that I'm copying into it.
I've loaded the code from a file into an array before and then pushed it into the string (probably not the best choice, but easiest for me right now), using the following code.
contentArray=Array.new
inputFile=File.open("my-site.html")
inputFile.each{|line| contentArray<<line}
inputFile.close
Now when I execute the first command to fill in the text_field, it slowly types in all the letters (is there an easy way to speed this up?), but after 692 characters it stops in the middle of the sentence.
[I pasted the text that was entered into charcounter.com, that's how I know this number.]
Where is the problem? Is ruby giving my strings a limited size for some reason? Can I somehow lift this barrier?
Is there another way to fill the text_field?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试 .value 方法
browser.text_field(:id => "text").value=(open('my-site.html') { |f| f.read })
或者
我我认为元音变音等的打印错误与您的计算机上的代码页设置和您正在读取的文件有关。您可能必须尝试从一个代码页到另一个代码页...我猜您的源文件是 CP850 甚至可能是 UTF-8,我认为您需要西欧语才能获得变音符号...但作为澳大利亚人,我真的没有想法=)
http://en.wikipedia.org/wiki/ISO_8859
例如
Try the .value method
browser.text_field(:id => "text").value=(open('my-site.html') { |f| f.read })
OR
I'm thinking the misprinting of umlauts etc is something to do with the codepage settings on your machine and the file you're reading from. You might have to experiment going from one code page to another ... I'm guessing your source file is CP850 or perhaps even UTF-8 and I think you need western european to get umlauts... but being Australian I really have no idea =)
http://en.wikipedia.org/wiki/ISO_8859
e.g.