大家每次将应用更新到新版本时,都应该显示有关用户在使用应用之前必须接受的条款的消息。但如果他已经在之前的版本中接受了该消息,它就不会再出现了。
我试图像这样做一个限制:
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 :(得分:3)
你的比较是错误的。第一行应大于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();