[英]How can I manage slow textarea speed with Watir-Webdriver in Firefox, linux?
I am using Ruby 1.8.7, Watir-Webdriver 0.6.1, Arch Linux, Firefox 14 我正在使用Ruby 1.8.7,Watir-Webdriver 0.6.1,Arch Linux,Firefox 14
I have read a lot of answers and examples in this topic, but none of them worked for me. 我已经阅读了很多有关此主题的答案和示例,但是没有一个对我有用。 When I want to paste a large piece of data (only about 15 lines of text) into a textarea it is terrible slow. 当我想将大量数据(仅约15行文本)粘贴到文本区域时,速度太慢了。 As I don't want typing emulation, I would like the maximum available speed, so I tried to set the variable "browser.speed = :zippy" but it seems don't work in Watir-Webdriver, only an error message appears: "undefined method `speed=' for #" 因为我不想键入仿真,所以我想要最大可用速度,所以我尝试设置变量“ browser.speed =:zippy”,但似乎在Watir-Webdriver中不起作用,仅出现一条错误消息: “#的未定义方法'speed ='”
Then I tried to set native_events to false, an error message arises again: "undefined method `native_events' for #" so I am a bit confused. 然后我尝试将native_events设置为false,再次出现错误消息:“#的未定义方法'native_events'”,所以我有点困惑。
This is my whole code snippet 这是我的整个代码段
require 'rubygems'
require 'watir-webdriver'
require 'xmlsimple'
default_profile = Selenium::WebDriver::Firefox::Profile.from_name "default"
default_profile.native_events = false
default_profile['javascript.enabled']=false
browser = Watir::Browser.new :ff, :profile => default_profile
browser.speed = :zippy
line 5. and 6. and 8. all throw an error message. 第5、6和8行都抛出错误消息。
At last I tried to edit text_field.rb as it is mentioned in this answer (http://stackoverflow.com/questions/5000164/firewatir-textfield-set-very-slow) but it is in a .gem file and in a tar.gz. 最后,我尝试编辑text_field.rb,因为它在此答案中提到(http://stackoverflow.com/questions/5000164/firewatir-textfield-set-very-slow),但它位于.gem文件和tar.gz。 I unzipped but I am unable to find the relevant lines: 我解压缩了,但是找不到相关的行:
# encoding: utf-8
module Watir
class TextField < Input
include UserEditable
attributes Watir::TextArea.typed_attributes
remove_method :type # we want Input#type here, which was overriden by TextArea's attributes
private
def locator_class
TextFieldLocator
end
def selector_string
selector = @selector.dup
selector[:type] = '(any text type)'
selector[:tag_name] = "input or textarea"
selector.inspect
end
end
module Container
def text_field(*args)
TextField.new(self, extract_selector(args).merge(:tag_name => "input"))
end
def text_fields(*args)
TextFieldCollection.new(self, extract_selector(args).merge(:tag_name => "input"))
end
end # Container
class TextFieldCollection < InputCollection
private
def locator_class
TextFieldLocator
end
def element_class
TextField
end
end # TextFieldCollection
end
For large strings, I would recommend getting the text into the system clipboard and then paste into the text field. 对于大字符串,我建议将文本放入系统剪贴板,然后粘贴到文本字段中。
On OS X, the pbcopy
command line utility can be used for this: 在OS X上,可以将pbcopy
命令行实用程序用于此目的:
IO.popen("pbcopy", "w") { |io| io << long_string }
browser.text_field.send_keys([:command, 'v'])
I'm sure there are Linux equivalents that work equally well (and you would need to use [:control, 'v']
instead. 我敢肯定,有Linux等效产品也能很好地工作(并且您需要使用[:control, 'v']
代替。
I had the same issue when trying to run IE with watir-webdriver. 尝试使用watir-webdriver运行IE时遇到相同的问题。 I managed to make it run a little faster by editing the \\Ruby193\\lib\\ruby\\gems\\1.9.1\\gems\\watir-webdriver-0.6.2\\lib\\watir-webdriver\\browser.rb file and add this, before the def initialize(browser = :firefox, *args): 通过编辑\\ Ruby193 \\ lib \\ ruby \\ gems \\ 1.9.1 \\ gems \\ watir-webdriver-0.6.2 \\ lib \\ watir-webdriver \\ browser.rb文件并添加此文件,我设法使其运行得更快def初始化(浏览器=:firefox,* args):
# Run fast
$FAST_SPEED = ARGV.delete('-f')
@@speed = $FAST_SPEED ? :fast : :slow
def self.speed
return :fast if $FAST_SPEED
@@speed
end
def self.speed= x
$FAST_SPEED = nil
@@speed = x
end
def initialize_options
self.speed = browser.speed
@ole_object = nil
@page_container = self
@error_checkers = []
@url_list = []
end
def speed= how_fast
case how_fast
when :zippy then
@typingspeed = 0
@pause_after_wait = 0.01
@type_keys = false
@speed = :fast
when :fast then
@typingspeed = 0
@pause_after_wait = 0.01
@type_keys = true
@speed = :fast
when :slow then
@typingspeed = 0.08
@pause_after_wait = 0.1
@type_keys = true
@speed = :slow
else
raise ArgumentError, "Invalid speed: #{how_fast}"
end
end
def speed
return @speed if @speed == :slow
return @type_keys ? :fast : :zippy
end
# deprecated: use speed = :fast instead
def set_fast_speed
self.speed = :fast
end
# deprecated: use speed = :slow instead
def set_slow_speed
self.speed = :slow
end
After that I modified def goto(uri) with: 之后,我用以下命令修改了def goto(uri):
def goto(uri)
uri = "http://#{uri}" unless uri =~ URI.regexp
@driver.navigate.to uri
run_checkers
initialize_options
url
end
It works a little faster, and I don't know if it is the best solution, as I just started with watir. 它的工作速度更快,但我不知道它是否是最佳解决方案,因为我刚开始使用watir。
Hope it helps. 希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.