トップページ > Appium API(逆引き) > 【Appium Python】要素が見つかるまでの待ち時間を設定する

【Appium Python】要素が見つかるまでの待ち時間を設定する

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

「implicitly_wait」を実行することで、指定したドライバの要素が見つかるまでの待ち時間を設定出来ます。

詳しくは「指定したドライバの要素が見つかるまでの待ち時間を設定する」参考にしてください。

説明

◆メソッド
  ○要素が見つかるまでの待ち時間を設定する
       ・driver.implicitly_wait(30)
◆備考 ー

◆その他「Appium API」
  ・キーボード非表示と表示判定
  ・Androidデバイスにキーボード入力する

サンプル

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)

#要素が見つかるまでの時間を15秒に設定
test_session.implicitly_wait(15)
#存在しないIDを指定し約15秒後にExceptionが発生するか確認
element = test_session.find_element(AppiumBy.ID, "xyz")
※Appium v2.0.0-beta.55で動作確認をしています

実行結果(15秒後にExceptionが発生)

Traceback (most recent call last):
  File "c:\AppiumTest\main3.py", line 19, in 
    element = test_session.find_element(AppiumBy.ID, "xyz")
  File "C:\Users\aoita\AppData\Local\Programs\Python\Python310\lib\site-packages\appium\webdriver\webdriver.py", line 383, in find_element
・
・
・

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