有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何使用if/else在屏幕上显示时单击IOS按钮

嗨,每次应用程序更新到新版本时,它都会显示一条消息,说明用户在使用应用程序之前必须接受的条款。但如果他已经接受了之前版本中的信息,它就不会再出现了。 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();
}

但它不起作用。如果它没有出现在屏幕上,代码就会失败,并且不会点击驱动程序。findElement(By.xpath(“/*[@text='Cadastre-se com seu e-mail pessoal']))。单击(); 我该怎么做


共 (1) 个答案

  1. # 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();