hello-world
webエンジニアのメモ。とりあえずやってみる。

[Ruby]seleniumで遊んでみる

公開日時

Selenium で自動化したいことがあったので色々遊んでみました。

その時のメモです。

基本的な使い方は RubyでSeleniumを使ってスクレイピング を参考にさせていただきました。

  • インストール
gem install selenium-webdriver
  • http proxyを使いたい場合
profile = Selenium::WebDriver::Firefox::Profile.new
profile["network.proxy.type"] = 1
profile["network.proxy.http"] = "my-proxy"
profile["network.proxy.http_port"] = 80
driver = Selenium::WebDriver.for(:firefox, :profile => profile)
  • socks proxyを使いたい場合
profile = Selenium::WebDriver::Firefox::Profile.new
profile["network.proxy.type"] = 1
profile["network.proxy.socks"] = "localhost"
profile["network.proxy.socks_port"] = 1080
driver = Selenium::WebDriver.for(:firefox, :profile => profile)
  • ページ読み込み
driver.navigate.to "https://www.google.co.jp"
  • name="sample_selectbox"となっているselect boxの値を1に設定
Selenium::WebDriver::Support::Select.new(driver.find_element(:name, 'sample_selectbox')).select_by(:value, '1')
  • name="sample_input"となっているinput textにtestと入力
driver.find_element(:name, 'sample_input').send_keys('test')
  • name="submit"をクリック
driver.find_element(:name, 'submit').click
  • jsを実行 (アラートを表示)
driver.execute_script("return alert('sample');")

参考


Related #Ruby

AWS SAMを使って署名付きURL発行APIを作る

S3の署名付きURL発行機能の検証を兼ねて、S3のキーをパラメータとして受け取り、署名付きURLを発行するAPIを作ってみました。

Rails Application Templateを使ってみた

やろうやろうと先延ばしにしていたRails Application Templateを使ってみました。

bundle install 時に An error occured while installing json (1.7.7)

mac で bundle install を実行した際に下記エラーが発生