请问我在使用appium进行滑动操作时,如何在向下滑动APP加载动态数据的同时,获取的数据不会重复呢?


上面这个动图就是最终想要实现的效果

from appium import webdriver
from appium.webdriver.extensi**.android.nativekey import AndroidKey

desired_caps = {
‘platformName’: ‘Android’, # *被测手机是安卓
‘platformVersion’: ‘7’, *# *手机安卓版本
‘deviceName’: ‘huawei7’, *# *设备名,安卓手机可以随意填写
‘appPackage’: ‘com.ss.android.article.lite’, *# *启动APP Package名称
‘appActivity’: ‘.activity.SplashActivity’, *# *启动Activity名称
‘unicodeKeyboard’: True, *# *使用自带输入法,输入中文时填True
‘resetKeyboard’: True, *# *执行完程序恢复原来输入法
‘noReset’: True, *# *不要重置
App
*’newCommandTimeout’: 6000,
‘automationName’: ‘UiAutomator2’
*# ‘app’: r’d:\apk\bili.apk’,
*}

# 连接Appium Server**,初始化自动化环境
*driver = webdriver.Remote(‘localhost:4723/wd/hub', desired_caps)
driver.implicitly_wait(5)
def getSize(
driver):
x = *driver
.get_window_size()[‘width’]
y = driver.get_window_size()[‘height’]
return (x, y)

# **屏幕向上滑动
*def swipeUp(
driver, *t=1000):
l = getSize(driver)
x1 = int(l[0] * 0.5) # x**坐标
*y1 = *int
(l[1] * 0.75) # 起始y**坐标
*y2 = *int
(l[1] * 0.25) # 终点y*坐标
*
driver
.swipe(x1, y1, x1, y2, t)

# **屏幕向下滑动
*def swipeDown(
driver, *t=1000):
l = getSize(driver)
x1 = int(l[0] * 0.5) # x**坐标
*y1 = *int
(l[1] * 0.25) # 起始y**坐标
*y2 = *int
(l[1] * 0.75) # 终点y*坐标
*
driver
.swipe(x1, y1, x1, y2, t)
while True: swipeUp(driver)
results = driver.find_elements_by_xpath(“//android.widget.TextView”)
for item in results:
```python
from appium import webdriver
from appium.webdriver.extensi**.android.nativekey import AndroidKey

desired_caps = {
‘platformName’: ‘Android’, # 被测手机是安卓
‘platformVersion’: ‘7’, # 手机安卓版本
‘deviceName’: ‘huawei7’, # 设备名,安卓手机可以随意填写
‘appPackage’: ‘com.ss.android.article.lite’, # 启动APP Package名称
‘appActivity’: ‘.activity.SplashActivity’, # 启动Activity名称
‘unicodeKeyboard’: True, # 使用自带输入法,输入中文时填True
‘resetKeyboard’: True, # 执行完程序恢复原来输入法
‘noReset’: True, # 不要重置App
‘newCommandTimeout’: 6000,
‘automationName’: ‘UiAutomator2’

# 'app': r'd:\apk\bili.apk',

}

连接Appium Server,初始化自动化环境

driver = webdriver.Remote(‘localhost:4723/wd/hub', desired_caps)
driver.implicitly_wait(5)
def getSize(driver):
x = driver.get_window_size()[‘width’]
y = driver.get_window_size()[‘height’]
return (x, y)

屏幕向上滑动

def swipeUp(driver, t=1000):
l = getSize(driver)
x1 = int(l[0] * 0.5) # x坐标
y1 = int(l[1] * 0.75) # 起始y坐标
y2 = int(l[1] * 0.25) # 终点y坐标
driver.swipe(x1, y1, x1, y2, t)

屏幕向下滑动

def swipeDown(driver, t=1000):
l = getSize(driver)
x1 = int(l[0] * 0.5) # x坐标
y1 = int(l[1] * 0.25) # 起始y坐标
y2 = int(l[1] * 0.75) # 终点y坐标
driver.swipe(x1, y1, x1, y2, t)
以下这里就是在滑动屏幕,但获取到的数据是重要,该如何滑动时,APP加载数据后,我得到是不重复的数据呢
while True: swipeUp(driver)
results = driver.find_elements_by_xpath(“//android.widget.TextView”)
for item in results:
print(item.text)

```print(item.text)
目前如果我使用上面的循环,得到是数据是重要,请教大礼,要如何实现下翻的同时,得到的数据不重复呢?

讨论数量: 2
Jason990420

代码乱了

2年前 评论

不知道你想要获取的具体数据为什么,单从数据重复这块来说的话,建议你使用set函数来对获取到的数据进行去重处理

2年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!