トップページ > Appium API(逆引き) > 【Appium Python】画面向きの設定と取得

【Appium Python】画面向きの設定と取得

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

画面の向きにはPORTRAIT(縦向き)とLANDSCAPE(横向き)の2種類があり、制御しているアプリケーションに対してそれぞれ設定することが出来ます。


また、現在の画面向き情報を取得することも出来ます。以下のサンプルコードではデフォルトの画面向き情報(PORTRAIT)を取得後、LANDSCAPE(横向き)に設定しその設定が反映されているかを確認しています。

説明

◆メソッド
  ○画面向きの設定
       ・driver.orientation = "LANDSCAPE" または
       ・driver.orientation = "PORTRAIT"
      
  ○画面設定情報の取得
       ・screen_info = driver.orientation
◆備考
  ・ー
◆その他「Appium API」
  ・id属性から要素を取得しクリックする
  ・XPathから要素を取得する

サンプル

from appium import webdriver

# 接続したいアプリ情報を変数に格納
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)

# 現在の画面向き情報を取得
screen = test_session.orientation
print(screen) # PORTRAIT
# 画面向き情報を設定
test_session.orientation = "LANDSCAPE"
# 現在の画面向き情報を再び取得
screen = test_session.orientation
print(screen) # LANDSCAPE
※Appium v2.0.0-beta.55で動作確認をしています

実行結果

orientaion1
yajirushi
orientaion2

Warning: Invalid argument supplied for foreach() in /home/users/1/monda-muki/web/seleniumqref.com/api/appium_python/device/setting_getting_screen_orientation-AppiumPython.html on line 171

Appium PythonAPI TOP10
過去1週間(4/18~4/24)

    カテゴリー

    環境構築

    APIリファレンス

    その他

    ページ上部へ戻る
    トップページ > Appium API(逆引き) > 【Appium Python】画面向きの設定と取得
    Copyright © 2016- Seleniumクイックリファレンス All Rights Reserved