appium自动化之获取剪切板数据

appium关于复制用户主页地址,无法拿到数据的问题,可以通知复制粘贴来解决:

(1)获取剪切板数据(推荐)

import win32con
import win32clipboard as w
w.OpenClipboard()
d = w.GetClipboardData(win32con.CF_TEXT)
url = d.decode('GBK')

(2)复制粘贴

from appium.webdriver.common.touch_action import TouchAction

input_merchant_url = WebDriverWait(driver, timeout=10, poll_frequency=0.5).until( lambda x: x.find_element_by_id('com.dianping.v1:id/search_hint'), message='输入商家地址超时') action = TouchAction(driver) action.long_press(input_merchant_url,duration=2000).wait(1000).perform() #长按弹出粘贴按钮 time.sleep(1) driver.tap([(172,324)],500) #点击粘贴 time.sleep(1)
merchant_url_content = WebDriverWait(driver, timeout=10, poll_frequency=0.5).until(
lambda x: x.find_element_by_id('com.dianping.v1:id/search_keyword_edit'), message='获取商家地址超时')
merchant_url = merchant_url_content.__getattribute__('text')

 

posted @ 2020-08-25 11:17  Eliphaz  阅读(1274)  评论(0编辑  收藏  举报