Appium等待元素出现

使用场景:在某些加载或者是需要一些耗时的操作之后才能获取到的控件

python:

def wait_element(driver, time, element_by, element, msg):
        """
        等待元素出现
        :param driver: driver
        :param time: 等待时间
        :param element_by: 元素类型
        :param element: 元素关键字
        :param msg: 输出信息
        :return:
        """
        WebDriverWait(driver, time).\
            until(expected_conditions.presence_of_element_located((element_by, element)),msg)

#调用
wait_element(self.deriver, 10, By.ID, "com.xxx.xxx.ceshi:id/main_select_index_rb", "没有发现xxxx...")

java:

public boolean waitForAeTextAppear(String text, int timeOutInSeconds) {
	try {
		WebDriverWait wait = new WebDriverWait(mDriver, timeOutInSeconds);
		wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(String.format("//*[@text='%s']", text))));
		return true;
	} catch (Exception e) {
		return false;
	}
}

这里随便写了下,具体的一些使用场景还需自行封装

参考:https://testerhome.com/topics/13620

https://blog.csdn.net/meyoung01/article/details/43056069



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值