java - 如果 IOS 按钮出现在屏幕上,如何使用 if/else 来单击它

标签 java ios xpath appium

您好,每次应用程序更新到新版本时,它都应该显示一条消息,说明用户在使用该应用程序之前必须接受的条款。但是如果他已经在以前的版本中接受了消息,那么它就不会再出现了。 screenshot

我试着做这样的限制:

Boolean Allow = driver.findElements(By.xpath("//[@id=‘Allow’]")).size()<0;
if (Allow.TRUE) {
new WebDriverWait(driver, 30, esperandogif).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//[@text=‘Allow’]"))).click();
else {
driver.findElement(By.xpath("//[@text=‘Cadastre-se com seu e-mail pessoal’]")).click();
driver.findElement(By.xpath("//[@placeholder=‘Email’]")).sendKeys("ashutosh@ashutosh.com.br");
driver.swipe(165, 759, 175, 534, 1234);
driver.findElement(By.xpath("//[@placeholder=‘Senha’]")).sendKeys(“lucasmoreira”);
driver.findElement(By.xpath("//[@placeholder=‘Confirmer Senha’]")).sendKeys(“lucazmoreira”);
driver.swipe(309, 856, 390, 406, 888);
driver.findElement(By.xpath("//[@placeholder=‘Nome e Sobrenome’]")).sendKeys(“teste”);
driver.findElement(By.xpath("//[@placeholder=‘CPF’]")).sendKeys(“12345678901”);
driver.swipe(168, 946, 334, 615, 2240);
driver.findElement(By.xpath("//[@placeholder=‘Data de Nascimento (dd/mm/aaaa)’]")).click();
try{Thread.sleep(threadSleep);} catch(Exception ignore){}
//driver.findElement(By.xpath("//[@text=‘2018’]")).click();
// driver.findElement(By.xpath("//[@text=‘2020’]")).click();
driver.findElement(By.xpath("//[@id=‘Feito’]")).click();
driver.swipe(84, 887, 259, 493, 1461);
driver.findElement(By.xpath("//[@placeholder=‘Telefone’]")).sendKeys(“99999999999”);
driver.swipe(450, 812, 500, 640, 1292);
driver.findElement(By.xpath("//[@id=‘Cadastrar’]")).click();
System.out.println(“report URL : " + driver.getCapabilities().getCapability(“reportUrl”));
driver.quit();
}

但它不起作用。如果它没有出现在屏幕上,则代码失败并且它不会单击 driver.findElement(By.xpath(”//*[@text='Cadastre-se com seu e-mail pessoal']”) )。点击(); 我该如何做这个限制?

最佳答案

您的比较方向错误。第一行必须大于0,不能小于。

Boolean Allow = driver.findElements(By.xpath("//[@id=‘Allow’]")).size()>0;

您可能还应该通过 id 查找,因为它对您可用。

Boolean Allow = driver.findElements(By.id("Allow")).size()>0;

我用 isEmpty() 编写了这样的语句,发现它们更具可读性并且不容易出现此错误:

Boolean Allow = !driver.findElementsById("Allow")).isEmpty();

关于java - 如果 IOS 按钮出现在屏幕上,如何使用 if/else 来单击它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49490105/

相关文章:

java - 如何将 Jackson PropertyNamingStrategy 与 Immutables 库一起使用

ios - 如何使 UILabel 和 UITextField 字体大小相对于屏幕大小

ios - 无法将 NSRange 类型的值转换为预期的参数类型

xml - XPATH:使用IMPORTXML计数字符串的出现

java - 如何构建运行测试套件的 Maven 工件? 'sbt test' 是如何工作的?

java - 数组不显示所有元素

java - Java Map 中的 put() 函数如何工作?

objective-c - 将数组中的数据从一个 View 传输到另一个 View

c# - 使用 HtmlAgilityPack 从两个 html 节点之间获取文本

python - Xpath 查询 'like' 替换