LoginSignup
2
4

More than 1 year has passed since last update.

Seleniumで座標を0,0に移す方法

Last updated at Posted at 2022-11-22

PythonでSeleniumのActionchainsのmove_by_offsetを使って画面の左上からの座標を指定してクリックしようとする際に、2回目以降だと現在の座標からの位置になってしまいうまくいきませんでした。
また、move_to_elementも要素の中央への移動しかできず苦戦していました。
今回その解決策を見つけたので共有します。

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

html = driver.find_element(By.XPATH,'/html')
ActionChains(driver).move_to_element(html).move_by_offset(-html.size['width']/2,-html.size['height']/2).perform()
 

以上です。

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