vendredi 30 juin 2017

If element is there do A else do B in selenium Java. So Stuck

I've been stuck on this for some time now. I've tried multiple ways to make this work an it just doesn't. The problem is that it gets to the if statement and just sits there and does nothing. The elementId does work as both pieces of code work if I remove the if test. One way I have tried:

if(!driver.findElement(By.id(elementId )).isDisplayed()){
   driver.findElement(By.id(downloadId)).click();
   TimeUnit.SECONDS.sleep(7);

 }else{
   CenterOnClick.testFail(elementId , driver);     
   FailScreenShot.test(caseId, driver, targetNumberCell);

 }

another way:

 if(driver.findElement(By.id(elementId)).isEmpty()){ //also used .size() > 0
   driver.findElement(By.id(downloadId)).click();
   TimeUnit.SECONDS.sleep(7);

 }else{
   CenterOnClick.testFail(elementId , driver);     
   FailScreenShot.test(caseId, driver, targetNumberCell);

 }

I've also tried switching things around. The button I am trying to click is only available if you've not downloaded the file more than twice in a month. After that an error message takes it place. Weird thing is if I change the code to this:

 if(driver.findElement(By.id(elementId )).isDisplayed()){
   CenterOnClick.testFail(elementId , driver);     
   FailScreenShot.test(caseId, driver, targetNumberCell);

 }else{
   driver.findElement(By.id(downloadId)).click();
   TimeUnit.SECONDS.sleep(7);


 }

it works, but only when the error message is showing. If the button is there it will still just sit there. Any help would be greatly appreciated as I've been at this for well over 16 hours. Thanks.

Aucun commentaire:

Enregistrer un commentaire