【问题标题】:Appium + Python on Android - scrolling doesn't workAndroid上的Appium + Python - 滚动不起作用
【发布时间】:2020-07-28 11:10:39
【问题描述】:

Android 上的 Appium + Python - 滚动 我有一个应用程序来自动化测试。场景如下所示:

我点击日期选择器 > 日历出现

我点击年份 > 出现年份列表

我想滚动到“1993”可见

“1993”年在屏幕上不可见,我想继续滚动直到它出现。我试过了

TouchAction(driver).press(x=746, y=1351).move_to(x=755, y=588).release().perform()

^但我不想使用坐标,而且我必须重复该行数次。

def set_year(self):
visibility = self.driver.find_element(By.XPATH, "//android.widget.TextView[@text='1993']").is_displayed()
while not visibility:
TouchAction(self.driver).press(x=746, y=1351).move_to(x=755, y=588).release().perform()
visibility = self.driver.find_element(By.XPATH, "//android.widget.TextView[@text='1993']").is_displayed()
else:
print("not found")

^但它一直在抛出 selenium.common.exceptions.NoSuchElementException: Message: An element could not be located on the page using the given search parameters 错误,因为正如我所说,它不可见

最好的方法是什么?

el = self.driver.find_element_by_xpath(<your_xpath>) driver.execute_script("mobile: scrollTo", {"element": el.id})

^这个给我一个错误,说元组没有id

【问题讨论】:

    标签: python selenium-webdriver appium


    【解决方案1】:

    每次找不到元素时,Appium 都会抛出错误。 因此,当您定义变量可见性时,您的脚本会在滑动之前停止。

    试试这个:

    def set_year(self):
        visibility = False
        i = 0
    
        while not visibility or i<100:
            i += 1
            try:
                visibility = self.driver.find_element(By.XPATH, 
                    "//android.widget.TextView[@text='1993']").is_displayed()
            except:
                TouchAction(self.driver).press(x=746, y=1351).move_to(x=755, 
                                               y=588).release().perform()
        if not visibility:
            print("not found")
    

    您的脚本将向下滚动,直到找到 1993 年。

    【讨论】:

      猜你喜欢
      • 2020-03-15
      • 2017-11-03
      • 2020-11-04
      • 2018-11-11
      • 2018-11-21
      • 1970-01-01
      • 2018-03-07
      • 1970-01-01
      • 2016-02-22
      相关资源
      最近更新 更多