将android屏幕元素滑动/滚动到selenium中的特定坐标

时间:2016-10-19 09:29:17

标签: java selenium testing automation appium

我正在自动化Android应用程序。我想通过滚动/滑动将元素放置到特定坐标来获取Android应用程序中屏幕的屏幕截图。我怎么能这样做?

1 个答案:

答案 0 :(得分:0)

使用以下代码可以帮助您:

driver.find_element_by_android_uiautomator('new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textContains("**/Put some text of scroll screen/**").instance(0))')

driver.save_screenshot("screenshot.png")

下面是我滚动的示例代码&截屏,我遇到任何问题:

from appium import webdriver

class test123():
    desired_caps = {}
    desired_caps['platformName'] = 'Android'
    desired_caps['platformVersion'] = '4.4.2'
    desired_caps['deviceName'] = 'XXXXXX'
    desired_caps['appPackage'] = 'net.one97.paytm'
    desired_caps['appActivity'] = 'net.one97.paytm.AJRJarvisSplash'
    driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
    driver.implicitly_wait(1000)

    driver.find_element_by_id('net.one97.paytm:id/edit_no').send_keys("9999990088")
    driver.find_element_by_id('net.one97.paytm:id/lyt_mob_op').click()

    driver.find_element_by_android_uiautomator(
        'new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textContains("Vodafone").instance(0))').click()

    driver.save_screenshot("screenshot.png")