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'相應地更新了我的代碼的最後一行。感謝史蒂夫的幫助。 :) –