Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Pythonでwebdriver

4,067 views

Published on

Using Python for webdriver.

Published in: Engineering
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download Full EPUB Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ACCESS WEBSITE for All Ebooks ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download EPUB Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download doc Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download Full EPUB Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ACCESS WEBSITE for All Ebooks ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download EPUB Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download doc Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download Full EPUB Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ACCESS WEBSITE for All Ebooks ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download EPUB Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download doc Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download Full EPUB Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ACCESS WEBSITE for All Ebooks ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download EPUB Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download doc Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download Full EPUB Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ACCESS WEBSITE for All Ebooks ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download EPUB Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download doc Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Pythonでwebdriver

  1. 1. PYTHONでWEBDRIVER を使ってみる 2015/1/21 岡山Python勉強会 @k5_yamayama
  2. 2. 山手 恵悟(やまやま) @k5_yamayama 岡山の某DBメーカー勤務 ユーザーCE→社内SE→企画開発→ →サーバー管理→営業に至る。 (これってフルスタック…?) 自己紹介
  3. 3. Okayama Engineers Community(通称:OITEC) 運営スタッフやってます。 岡山Python勉強会(通称:おっPy) 立ち上げスタッフ 主催者のはずの“#た”が福山に戻っちゃった で現在は、ほぼ主催者状態。 コミュニティ
  4. 4. はじめに 今回は、SeleniumのWebDriverを使って操作 の自動化について解説します。
  5. 5. 注意事項 本セッションは、やまやま個人が調査・検証した 結果を発表するもので、間違いやこれにより損害 が生じても一切責任を負いませんのでご了承くだ さい。
  6. 6. 今日の目的とゴール  目的 Seleniumの仕組みとWebDriverの使 い方を知ってもらう。  ゴール PythonとWebDriverを使ったWebサ イトの操作自動化を理解してもらう。
  7. 7. Seleniumとは?  ブラウザの操作を自動化する仕組み  IDEを使い、操作の自動化や内部解析を行い、結果 を取得/比較することができる。  FireFoxのプラグインとして動作するが他のブラウ ザでも操作可能。  WebDriverを使えばIDEを使わずに複数の言語でテ ストを書くことが可能 今回は、WebDriverを使ってテストする部分 について説明します。
  8. 8. まずはインストール  Selenium IDE  FireFoxのプラグインマネージャーにて検索し、インストー ル  WebDriver  Pythonのインストール(省略)  コマンドラインにて以下のコマンドを実行 pip install selenium
  9. 9. 動作確認 自動的にブラウザが起動し、指定されたURL表示されたらOK。 # -*- coding: utf-8 -*- from selenium import webdriver dropbox = webdriver.Firefox() dropbox.get('https://dropbox.com/')
  10. 10. 主なデータ取得の種類 主な値の取得メソッド find_element_by_class_name(name)→クラス名の取得 find_element_by_name(name)→エレメント名の取得 find_element_by_tag_name(name)→タグ名の取得 find_element_by_link_text(link_text)→リンクの取得 find_element_by_xpath(xpath)→xpathによる指定部分の取得 では、実際に取得するには?
  11. 11. Dropboxログイン画面文字を取得する 指定されたelementのテキストを取得 # -*- coding: utf-8 -*- from selenium import webdriver import codecs,sys sys.stdout = codecs.getwriter('cp932')(sys.stdout) dropbox = webdriver.Firefox() dropbox.get('https://dropbox.com/') d = dropbox.find_elements_by_class_name("subtitle") print d[0].text dropbox.quit() 指定のエレメントがリストで 帰ってくる
  12. 12. 操作系の処理 主な操作系メソッド find_element_by_xpath(path).send_keys(‘aaa’) →取得した内容に文字列をセット find_element_by_xpath(path).click() →取得した内容をクリック では、実際にコードは?
  13. 13. Dropboxに自動的にログインする # -*- coding: utf-8 -*- from selenium import webdriver import time import settings dropbox = webdriver.Firefox() dropbox.get('https://www.dropbox.com/login') time.sleep(5) dropbox.find_element_by_xpath( '//input[@class="text-input-input autofocus"]') .send_keys(settings.DROPBOX_ID) time.sleep(2) dropbox.find_element_by_xpath( '//input[@class="password-input text-input-input"]') .send_keys(settings.DROPBOX_PWD) time.sleep(2) dropbox.find_element_by_xpath( '//button[@type="submit"]').click()
  14. 14. 使ってみた所感  自動化スクリプト便利!  ブラウザごとにドライバを変更すればいけるので ちょこっとブラウザ確認するときは楽。  HTMLの解析にデベロッパーツール必須。  Findする際は、Xpath指定したほうがクリティカル にtagを取得しやすい感じがする。  IEは一応動くが…  日本語の比較などを行うときは注意が必要
  15. 15. まとめ  自動化やUIテストを行うときは比較的容易に利用が できる。  HTMLの作りにより処理内容が左右される。  操作や処理がわからない場合は、SeleniumのIDE を使えばある程度の処理は理解できる。  読み込みリソースが多い場合は、処理が間に合わな い場合があるので注意が必要。
  16. 16. 参考URL Selenium site http://www.seleniumhq.org/ Selenium document http://docs.seleniumhq.org/projects/webdriver/
  17. 17. ご清聴ありがとうございまし た。

×