【问题标题】:How to use a if/else to click on IOS button if it appears on the Screen如果 IOS 按钮出现在屏幕上,如何使用 if/else 单击它
【发布时间】:2018-09-04 12:25:43
【问题描述】:

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

我试图做这样的限制:

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']") )。点击(); 我该怎么做?

【问题讨论】:

    标签: java ios xpath appium


    【解决方案1】:

    你的比较是错误的。第一行应该大于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();
    

    【讨论】:

    • 添加到这个答案,如果你使用 By.id 和 Appium,这是一个本机应用程序(你似乎没有提到那部分),那么它将能够找到元素,但是对于By.xpath,它只会匹配标记名“id”而不会找到“resource-id”,这可能就是它的真正含义。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-21
    • 2021-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多