There is no problem with the automatic operation in front of the program, only here there are always 500 exceptions, and there is no problem with loading.
# 查找所有android.widget.Button的text
def find_elements_with_retry(driver, by, value, retries=3, delay=5):
for attempt in range(retries):
try:
elements = driver.find_elements(by, value)
if elements:
return elements
except Exception as e:
logging.error(f"Error finding elements: {str(e)}")
time.sleep(delay)
return []
elements = find_elements_with_retry(driver, By.CLASS_NAME, "android.widget.Button")
Error reported as follows:
[da50e1b9][HTTP] --> POST /session/da50e1b9-f1d3-43c0-9bca-5d6c52cc333e/elements {"using":"class name","value":"android.widget.Button"}
[da50e1b9][AndroidUiautomator2Driver@5d3b] Calling AppiumDriver.findElements() with args: ["class name","android.widget.Button","da50e1b9-f1d3-43c0-9bca-5d6c52cc333e"]
[da50e1b9][AndroidUiautomator2Driver@5d3b] Valid locator strategies for this request: xpath, id, class name, accessibility id, css selector, -android uiautomator
[da50e1b9][AndroidUiautomator2Driver@5d3b] Waiting up to 60000 ms for condition
[da50e1b9][AndroidUiautomator2Driver@5d3b] Matched '/elements' to command name 'findElements'
[da50e1b9][AndroidUiautomator2Driver@5d3b] Proxying [POST /elements] to [POST http://127.0.0.1:8203/session/f5381813-6ee5-4026-b7d0-e74f1eebd95a/elements] with body: {"strategy":"class name","selector":"android.widget.Button","context":"","multiple":true}
[a5a88ae7][HTTP] --> GET /session/a5a88ae7-dc12-4d55-a66b-bb46f6e36b8c/timeouts {}
[a5a88ae7][AppiumDriver@248e] Encountered internal error running command: NoSuchDriverError: A session is either terminated or not started
at asyncHandler (D:devnvmv22.2.0node_modulesappiumnode_modules@appiumbase-driverlibprotocolprotocol.js:309:15)
[a5a88ae7][HTTP] <-- GET /session/a5a88ae7-dc12-4d55-a66b-bb46f6e36b8c/timeouts 404 2 ms - 2835
[da50e1b9][AndroidUiautomator2Driver@5d3b] Got response with status 500: {"sessionId":"f5381813-6ee5-4026-b7d0-e74f1eebd95a","value":{"error":"unknown error","message":"Timed out after 15527ms waiting for the root AccessibilityNodeInfo in the active window. Make sure the active window is not constantly hogging the main UI thread (e.g. the application is being idle long enough), so the accessibility manager could do its work","stacktrace":"io.appium.uiautomator2.common.exceptions.UiAutomator2Exception: Timed out after 15527ms waiting for the root AccessibilityNodeInfo in the active window. Make sure the active window is not constantly hogging the main UI thread
[da50e1b9][HTTP] <-- POST /session/da50e1b9-f1d3-43c0-9bca-5d6c52cc333e/elements 500 15544 ms - 4613
Environment
[Appium] Welcome to Appium v2.11.1
[Appium] The autodetected Appium home path: C:Users13320.appium
[Appium] Attempting to load driver uiautomator2...
[Appium] Requiring driver at C:Users13320.appiumnode_modulesappium-uiautomator2-driverbuildindex.js
[Appium] AndroidUiautomator2Driver has been successfully loaded in 2.347s
[Appium] Appium REST http interface listener started on http://0.0.0.0:4723
[Appium] Available drivers:
[Appium] - [email protected] (automationName 'UiAutomator2')
New contributor
quiet is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.