如何使pycharm确认从移动应用程序到移动浏览器的重定向已经完成?



到处找都找不到答案。

场景:Android应用程序的自动化脚本

Pre-req:在Android应用程序中点击一个带有Mobile浏览器重定向的按钮

我想让脚本检查什么:如果通过检查是否显示了Mobile浏览器页面中的元素(带有文本或链接或xpath),将用户成功重定向到Mobile浏览器

脚本是为应用程序制作的,但是我找不到正确的代码来检查浏览器页面

中的元素我将在这里张贴一小部分代码从我的自动化脚本为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可以使用。

我认为问题就在这里,

element = driver.find_elements_by_xpath("//xpath here,*[text()='Choose your payment method']")

如果你注意的话你会看到xpath("")中的xpath here

应该是:-

element = driver.find_elements_by_xpath("//*[text()='Choose your payment method']")

现在这里有一个list

print(len(element))

像这样打印大小或者做任何你想做的事。一切由你决定。

更新1:看了HTML后,我认为这应该适合你。

Xpath

//section[contains(@class,'gold-payment-methods')]/descendant::strong

代码中:-

element = driver.find_element_by_xpath("//section[contains(@class,'gold-payment-methods')]/descendant::strong")
element.click()

最新更新