4

我正在使用 selenium webdriver 和 ruby​​。长话短说,我正在开发一个 Web 应用程序,单击按钮即可将文本字段中的所有数据复制到剪贴板。我想访问该数据并比较是否存在字符串。

我已经安装了剪贴板和 win32/剪贴板 gems。这是我的代码

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
4

2 回答 2

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

请参阅:https ://rubygems.org/gems/clipboard

于 2015-06-25T17:03:37.970 回答
1

首先安装'win32-clipboard':

gem install win32/clipboard

然后执行以下操作:

require 'win32-clipboard'
include Win32 

abc = Clipboard.data
puts abc
于 2013-07-06T08:17:43.627 回答