LoginSignup
6
4

More than 3 years have passed since last update.

Selenium 画面外の要素を画面内に表示させる

Posted at

はじめに

本記事は「要素は存在するけど、クリック操作できない」という場合の対処法です。
↓こんな感じのエラーの時です。

unknown error: Element is not clickable at point

要素が画面外にあるので、スクロールして表示させる

要素が画面表示外にあるため、操作できなくなっているはずです。
なので、画面内に表示するようスクロールしてあげます。

要素を表示するようスクロール
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains

# クローム起動(カレントディレクトリにwebdriverを設置済)
driver = webdriver.Chrome()

# ページの表示
driver.get("https://==========================")

# クリックするとエラーになる要素の取得
element = driver.find_element_by_xpath("/html/body/div/div")

# 要素を表示するようスクロール
ActionChains(driver).move_to_element(element).perform()

# クリック
element.click()

画面下に指定した要素がひょこっと現れて操作できるようになります。

6
4
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
6
4