我正在使用selenium webdriver和ruby。简而言之,我正在开发一个Web应用程序,只需单击一个按钮就可以将文本字段中的所有数据复制到剪贴板。我想访问该数据并比较字符串是否存在。
我已经安装了剪贴板和win32 /剪贴板gems.Here是我的代码
include Win32
abc = Clipboard.data
em = " ooyalaPlayer = OO.Player.create('playerContainer',"
puts 'true' if abc.include? em
这是错误堆栈
$ jruby tests/embed_add_remove_playlist.rb -b firefox -a staging
ui-test-support will place screenshots and additional logs under:
results_dir=E:/testing/behavioral_tests/themebuilder/results
c:/jruby-1.7.4/lib/ruby/shared/rubygems/custom_require.rb:36: Use RbConfig inste
ad of obsolete and deprecated Config.
LoadError: no such file to load -- win32-clipboard
require at org/jruby/RubyKernel.java:1054
require at c:/jruby-1.7.4/lib/ruby/shared/rubygems/custom_require.rb:36
(root) at E:/testing/behavioral_tests/themebuilder/lib/embed_helper.rb:8
require at org/jruby/RubyKernel.java:1054
require at c:/jruby-1.7.4/lib/ruby/shared/rubygems/custom_require.rb:36
(root) at tests/embed_add_remove_playlist.rb:8
答案 0 :(得分:2)
如果您可以访问linux或osx系统,则可以执行以下操作:
将文字写入如下文件:
IO.write('/tmp/msg.txt', 'hi')
像这样读回来:
IO.read('/tmp/msg.txt')
我经常想把文件读到我的剪贴板***
Clipboard.copy IO.read('/tmp/msg.txt')
有时候,我想将剪贴板中的内容写入文件***
IO.write('/tmp/msg.txt', Clipboard.paste)
***假设您已安装剪贴板gem
答案 1 :(得分:1)
首先安装'win32-clipboard':
gem install win32/clipboard
然后执行以下操作:
require 'win32-clipboard'
include Win32
abc = Clipboard.data
puts abc