トップページ > Appium API(逆引き) > 【Appium Python】デバイスロック関連

【Appium Python】デバイスロック関連

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

デバイスに対して「lock」を実施することで、画面ロックがかかった状態になります。逆に「unlock」で画面ロックを解除できます。


「is_locked」の実行で画面ロックがかけられているかを判定(True or False)することが出来ます。

説明

◆メソッド
  ○デバイスロック
       ・driver.lock()

  ○デバイスアンロック
       ・driver.unlock()

  ○デバイスロック情報の取得
       ・device_lock_info = driver.is_locked
◆備考
  ・ー
◆その他「Appium API」
  ・画面向きの設定と取得
  ・id属性から要素を取得しクリックする

サンプル

from appium import webdriver
import time

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

# デバイスをロック
test_session.lock()
# デバイスがロックされているか確認
device_lock_info = test_session.is_locked()
print(device_lock_info)  # True
# ロック状態で5秒待機
time.sleep(5)
# デバイスをアンロック
test_session.unlock()
# デバイスがロックされているか確認
device_lock_info = test_session.is_locked()
print(device_lock_info)  # False
※Appium v2.0.0-beta.55で動作確認をしています

実行結果

lock1
yajirushi
lock2

Fatal error: Uncaught Google_Service_Exception: Error calling GET https://www.googleapis.com/analytics/v3/data/ga?ids=ga%3A138132118&start-date=7daysAgo&end-date=yesterday&metrics=ga%3Apageviews&dimensions=ga%3ApageTitle%2C+ga%3ApagePath&sort=-ga%3Apageviews&max-results=1000: (403) User does not have sufficient permissions for this profile. in /home/users/1/monda-muki/web/seleniumqref.com/google-api-php-client-1-master/src/Google/Http/REST.php:110 Stack trace: #0 /home/users/1/monda-muki/web/seleniumqref.com/google-api-php-client-1-master/src/Google/Http/REST.php(62): Google_Http_REST::decodeHttpResponse(Object(Google_Http_Request), Object(Google_Client)) #1 /home/users/1/monda-muki/web/seleniumqref.com/google-api-php-client-1-master/src/Google/Task/Runner.php(174): Google_Http_REST::doExecute(Object(Google_Client), Object(Google_Http_Request)) #2 /home/users/1/monda-muki/web/seleniumqref.com/google-api-php-client-1-master/src/Google/Http/REST.php(46): Google_Task_Runner->run() #3 /home/users/1/monda-muki/web/seleniumqref in /home/users/1/monda-muki/web/seleniumqref.com/google-api-php-client-1-master/src/Google/Http/REST.php on line 110