LoginSignup
19
14

More than 5 years have passed since last update.

僕はどうしてもseleniumでコピーしたかった

Last updated at Posted at 2015-03-09

selenium webdriverで文章をコピーしたい!

でもseleniumにはコピーなんてコマンドなかった!(見落としてるだけかもしれない)

sendkeysでctrl+C やればいいやと思ったけどできない

ならばこうしてやるわ!!

環境:ubuntu12.04,python2.7,selenium,chrome

python
copy = driver.execute_script("return window.getSelection().toString();")

execute_scriptで選択範囲の文字を取り出して変数に代入

seleniumからjavascriptを実行させてコピーできました!!

ちなみに全選択はこう

python
driver.execute_script("document.execCommand('SelectAll');")
19
14
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
19
14