21
19

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

webdriverのuserAgentを変更する

Last updated at Posted at 2012-09-20

webdriver-user-agentをインストールしたら簡単に出来たのでメモ。。

以下gemをインストール

require 'selenium-webdriver'
require 'webdriver-user-agent'

  driver = UserAgent.driver(:browser => :chrome, :agent => :iphone, :orientation => :landscape)
  driver.get 'http://www.yahoo.co.jp/'
  driver.current_url.should == 'http://m.yahoo.co.jp/'

chromeブラウザが開いて、Yahooのサイトがiphoneと認識されて表示されます。
user-agentのオプションについてはこんなかんじ。

browser =>

  • :firefox (default)
  • :chrome

agent =>

  • :iphone (default)
  • :ipad
  • :android_phone
  • :android_tablet
  • :random

:orientation =>

  • :portrait (default)
  • :landscape
21
19
0

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
21
19

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?