1
我可以成功复制的文本复制到剪贴板,新文件也被在指定的路径创建,但被粘贴数据wrong.This数据被粘贴(文件:0x1ff09c8)如何将剪贴板内容粘贴到文件中?
我也尝试使用“的Win32 /剪贴板“,但得到一个错误”无法加载win32 /剪贴板“。
,因为我使用JRuby,所以我安装了宝石的Win32剪贴板
$ jruby -S gem install win32-clipboard
Building native extensions. This could take a while...
ERROR: Error installing win32-clipboard:
ERROR: Failed to build gem native extension.
c:/jruby-1.7.4/bin/jruby.exe extconf.rb
NotImplementedError: C extension support is not enabled. Pass -Xcext.enabled=tru
e to JRuby or set JRUBY_OPTS or modify .jrubyrc to enable.
(root) at c:/jruby-1.7.4/lib/ruby/shared/mkmf.rb:8
require at org/jruby/RubyKernel.java:1054
(root) at c:/jruby-1.7.4/lib/ruby/shared/rubygems/custom_require.rb:1
(root) at extconf.rb:7
Gem files will remain installed in c:/jruby-1.7.4/lib/ruby/gems/shared/gems/win3
2-api-1.4.8 for inspection.
Results logged to c:/jruby-1.7.4/lib/ruby/gems/shared/gems/win32-api-1.4.8/ext/g
em_make.out
我的代码
require 'clipboard'
WAIT.until { driver.find_element(:id, 'btnShowEmbedCode') }.click
sleep 3
em = WAIT.until { driver.find_element(:xpath, ".//*[@id='clipboardtext']") }
em.text
driver.find_element(:xpath, 'html/body/div[31]/div[1]/button').click
File.open('copy_embed_code.html', 'w') do |f|
f.truncate(0)
f << Clipboard.("#{f}")
end
是Win32剪贴板是给一个错误,所以我使用的剪贴板上的宝石。
上面的代码工作正常与IRB,但我不能在我的脚本中做同样的事情。
即使在irb中,我也不确定这将如何工作...首先你有一个文件'f','#{f}'是文件的对象ID,所以它应该看起来像File:0x1ff09c8这实际上是一个File对象ID。其次,Clipboard。(“some string”)不是剪贴板gem支持的格式...它期望Clipboard.copy或Clipboard.paste或Clipboard.clear ...我希望你的倒数第二行应该是'f <
SteveTurczyn
'File.open('copy_embed_code.html','w')do | f | f.truncate(0) f << Clipboard.paste end'相应地更新了我的代码的最后一行。感谢史蒂夫的帮助。 :) –