LoginSignup
13
10

More than 5 years have passed since last update.

Selenium Webdriver(Ruby) で ドラッグ&ドロップする方法

Posted at

あんまり理解できてないけどやり方だけわかったのでメモ。

環境(とりあえず動いたときのバージョン)

  • Ruby : 2.0.0p451
  • selenium-webdriver : 2.42.0
  • Firefox : 31
  • Chrome : 36
  • IE : 11

やりかた

ドライバつくるとき

setup
ff_profile  = Selenium::WebDriver::Firefox::Profile.new
capabilities = Selenium::WebDriver::Remote::Capabilities.firefox(:firefox_profile => ff_profile)

driver = Selenium::WebDriver.for :firefox,
                                 :desired_capabilities => capabilities

Chrome, IE の場合は、firefox の箇所をそれぞれ chrome, ie に変えればOK。

実際に D&D するとき

sourceをtargetまでD&Dするサンプル
source = driver.find_element(:id, "source_element")
target = driver.find_element(:id, "target_element")

driver.action.drag_and_drop(source, target).perform
13
10
4

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
13
10