LoginSignup
64
62

More than 5 years have passed since last update.

python × seleniumでID/PASS入力必要な画面に自動ログインしてみた

Posted at

はじめに

python × seleniumでID/PASS入力必要な画面に自動ログインを試した際の自分的なメモとなります。

参考にさせて頂いた記事

コード

login.py
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time

options = Options()
options.binary_location = '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'

driver = webdriver.Chrome(chrome_options=options)
driver.get('対象のURL')

# ID/PASSを入力
id = driver.find_element_by_id("ユーザID入力フィールドの要素")
id.send_keys("実際のID")
password = driver.find_element_by_id("パスワード入力フィールドの要素")
password.send_keys("実際のPASS")

time.sleep(1)

# ログインボタンをクリック
login_button = driver.find_element_by_name("ログインボタンの要素")
login_button.click()

# サイト内で他の画面に遷移させたければ
driver.get('画面遷移させたいURL')
64
62
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
64
62