0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【selenium】pythonでChromeドライバーを使ってブラウザを操作 入門編

Posted at

はじめに

今回はずっとやりたいなと思っていたChromeドライバーを使用してseleniumでブラウザ操作をするということを行った。
その時の備忘録としてここにまとめておく。

共通インポート

sample.py
from selenium import webdriver
from selenium.webdriver.common.by import By

クラス要素の取得 .find_element(By.CLASS_NAME, '')

sample.py
driver.find_element(By.CLASS_NAME, "login-btn")

ID要素の取得 .find_element(By.ID, '')

sample.py
driver.find_element(By.ID, "login-email")

要素の取得 .find_element(By.XPATH, '')

sample.py
driver.find_element(By.XPATH, 'XPATH値')

要素の取得 .find_element(By.TAG_NAME, '')

sample.py
driver.find_element(By.TAG_NAME, "option")

要素の取得 .find_element(By.NAME, '')

sample.py
driver.find_element(By.NAME, "email")

クリック操作 .click()

sample.py
loginBtn = driver.find_element(By.CLASS_NAME, "login-btn")
loginBtn.click()

まとめ

やはりpythonの技術に個人的には癖があるなぁと思った。が、pythonは意外と簡単に作れてしまうので、便利やなぁと感じた。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?