3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

よく使うもの

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys

Webドライバーを読み込み

# Chromeの場合
with webdriver.Chrome() as driver:
    ...
    
# Edgeの場合
with webdriver.Edge() as driver:
    ...
    
# Firefoxの場合
with webdriver.Firefox() as driver:
    ...

サイトを開く

driver.get("https://example.com")

要素を選択

driver.find_element(By.TAG_NAME,"h1")       # タグ名から
driver.find_element(By.CLASS_NAME,"class")  # クラスから
driver.find_element(By.ID,"id")             # idから

driver.find_elements(By.CLASS_NAME,"hoge")  # クラスから複数のタグを取得

要素をクリック

elm = driver.find_element(By.ID,"button")
elm.click()

キーを入力

driver.send_keys("hoge")
elm.send_keys(Keys.ENTER) # 特殊なキーはKeysを使用
3
1
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
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?