トップページ > Appium API(逆引き) > 【Appium Python】要素のXY座標とheightとwidthを取得する

【Appium Python】要素のXY座標とheightとwidthを取得する

【PR】業界トップクラスの「高単価報酬」「低マージン」を実現!レバテックフリーランス

取得した要素のXY座標とサイズを取得することが出来ます。座標を指定してクリックしたり、要素からのオフセットを指定してクリックもしくはドラッグ&ドロップする場合など、値を参考にすることが出来ます。

説明

◆メソッド
  ○要素のXY座標を取得する
       ・value = element.location

  ○要素のサイズを取得する
       ・value = element.size

  ○要素のサイズとX/Y座標を取得
       ・value = element.rect
◆備考
  ・ー
◆その他「Appium API」
  ・要素が見つかるまでの待ち時間を設定する
  ・キーボード非表示と表示判定

サンプル

from appium import webdriver
from appium.webdriver.common.appiumby import AppiumBy

#接続したいアプリ情報を変数に格納
desired_caps = {}
desired_caps["appium:app"] = "C:\\appium_test\\app-debug.apk"
desired_caps["platformName"] = "Android"
desired_caps["platformVersion"] = "12.0"
desired_caps["appium:deviceName"] = "PixelXLAPI31"
desired_caps["appium:automationName"] = "UiAutomator2"
#セッションの作成
test_session = webdriver.Remote(
    command_executor='http://localhost:4723/wd/hub',
    desired_capabilities= desired_caps)

#チェックボックスの要素(インターネット)を取得
element = test_session.find_element(AppiumBy.ID, "cb_internet")

#取得した要素のXY座標を取得
lc = element.location
print(lc) # {'x': 518, 'y': 1112}
#取得した要素のサイズを取得
sz = element.size
print(sz) # {'height': 168, 'width': 455}
#取得した要素のサイズとX/Y座標を取得
rc = element.rect
print(rc) # {'height': 168, 'width': 455, 'x': 518, 'y': 1112}
※Appium v2.0.0-beta.55で動作確認をしています

Warning: Invalid argument supplied for foreach() in /home/users/1/monda-muki/web/seleniumqref.com/api/appium_python/element/get_xy_coordinates_and_height-width_of_element-AppiumPython.html on line 174

Appium PythonAPI TOP10
過去1週間(4/20~4/26)

    カテゴリー

    環境構築

    APIリファレンス

    その他

    ページ上部へ戻る
    トップページ > Appium API(逆引き) > 【Appium Python】要素のXY座標とheightとwidthを取得する
    Copyright © 2016- Seleniumクイックリファレンス All Rights Reserved