【发布时间】:2021-10-31 22:24:20
【问题描述】:
到处搜索,但我找不到答案。
场景: 为 Android 应用程序完成的自动化脚本
前置要求: 单击带有移动浏览器重定向的 Android 应用程序中的按钮
我希望脚本检查的内容: 如果通过检查是否显示来自移动浏览器页面的元素(带有文本或链接或 xpath)将用户成功重定向到移动浏览器
脚本是为应用程序编写的,但我找不到正确的代码来检查浏览器页面中的元素
我将在此处发布我的 Android 应用自动化脚本中的一小部分代码:
from appium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support import expected_conditions as EC
import time
if __name__ == "__main__":
desired_cap = {
"platformName": "android",
"deviceName": "emulator-5554",
"appPackage": "com.project.ProjectName",
"appActivity": ".SplashActivity",
"automatorName": "UiAutomator2",
}
driver = webdriver.Remote ("http://localhost:4723/wd/hub",desired_cap)
#Get more gold button check
element =
driver.find_element_by_xpath("xpath here")
element.click()
print("Step 12. Get more gold button clicked")
pass
#??????Confirmation that Gold store was open IN BROWSER
wait = WebDriverWait(driver, 10)
element = driver.find_elements_by_xpath("//xpath here,*[text()='Choose your payment method']")
#wait.until(EC.visibility_of_any_elements_located((By.CLASS_NAME, "flx-j-c txt-up")))
for i in element:
if 'Choose your payment method' == i.text:
print('Step 13. User not on Me tab - PASS')
else: print('FAIL to redirect the user')
time.sleep(2)
driver.back()
pass
错误: selenium.common.exceptions.TimeoutException:消息:
我试图通过 xpath、class、text 来查找元素,没有 id 可用于此。
【问题讨论】:
标签: android selenium selenium-webdriver appium appium-android