Appium Appium + python 新手问题

cashian · 2017年05月11日 · 最后由 usky 回复于 2017年05月23日 · 1359 次阅读

最近开始学习 Appium 和 python ,之前用公司自己的框架写过一段时间的脚本 ,最近想用 Appium 实现,但是看了几个示例额程序,不是很明白 。

1.方法跟我之前用过的不一样,比如点击一个按钮,可通过 resourceIid . 也可以通过 text 。
例如 : d(resouceId = 'xxxxxxx').click.wait()
assert xxxxxxxxxxxxxxx
不知道 APpium 怎么实现点击,断言。。
有没有方法说明 ??
找了一个,不知道对不对。。不过是 java 的,python 怎么写 ?
http://blog.csdn.net/birdlee0524/article/details/52461347
http://www.cnblogs.com/lynn-li/p/6290734.html

求指点,最好有参照

coding:utf8

import logging
import histsimilar
import traceback
import time
import os
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException, WebDriverException
logging.basicConfig(filename='log.txt',level=logging.INFO)
success = True
desired_caps = dict()
desired_caps['browserName'] = 'iOS'
desired_caps['platform'] = 'Mac'
desired_caps['version'] = '6.1'
desired_caps['app'] = os.path.abspath('测试 app 的位置')
#def is_alert_present(wd):

   try:

       wd.switch_to_alert().text

       return True

   except:

       return False

def click(element):
element.click()
time.sleep(3)
logging.info(str(c) + ' time click ' + wd.page_source)
screenshot()
def send_keys(element, keys):
element.send_keys(keys)
time.sleep(3)
logging.info(str(c) + ' time click ' + wd.page_source)
screenshot()
def execute_script(script, args):
wd.execute_script(script, args)
time.sleep(3)
screenshot()
def mk_new_dir():
global path, base
base = '截图存放的位置'
if not os.path.isdir(base):
path = base + '0/'
os.mkdir(path)
return
path = base + str(len(os.listdir(base))) + '/'
c = 0
def screenshot():
global c, path
if not os.path.isdir(path):
os.mkdir(path)
wd.get_screenshot_as_file(path + str(c) + '.png')
c += 1
def compare():
dirs = list()
for dirname in os.listdir(base):
if os.path.isdir(base + dirname):
dirs.append((os.path.getmtime(base + dirname), dirname))
if len(dirs) < 3:
return

共收到 3 条回复 时间 点赞

顶顶顶

点击的话,定位到元素,然后使用 click() 就可以了
比如:find_element_by_id("XXXXX").click() 通过 id 来定位
定位的话有多种不同的方式,网上随便一搜就有了


用 try 来判断是否点击成功,最后断言结果

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册