jeudi 19 septembre 2019

ExpectedConditions.or function not working as expected

I have to test an e-shop. The users can add items to their cart. When the cart is empty, a special section with id "empty-basket" is created. If the cart is not empty, this section's id becomes "basket".

These are my two selectors

@FindBy(how = How.ID, using = "#empty-basket")
private WebElement conteneur_panier_vide;

@FindBy(how = How.ID, using = "#basket")
private WebElement conteneur_panier_non_vide;

To check if the bloc containing the elements is well formed, I check if there is one of the sections described above. I use this piece of code to do so:

this.wait.until(
    ExpectedConditions.or(
        ExpectedConditions.visibilityOf(conteneur_panier_vide),
        ExpectedConditions.visibilityOf(conteneur_panier_non_vide)
    )
);

However, this gives me an error

org.openqa.selenium.TimeoutException: Expected condition failed: waiting for at least one condition to be valid

Surprised, I tried this:

this.wait.until(ExpectedConditions.visibilityOf(conteneur_panier_vide))

on a page with an empty basket. It works, the WebElement is found.

I then tried this:

this.wait.until(
    ExpectedConditions.or(
        ExpectedConditions.visibilityOf(conteneur_panier_vide),
    )
);

And it works as well. It means that adding a non-existing element to the 'or' breaks it, which is exactly the opposite of what it should be.

Does anyone have an idea of why my code is not working?

Aucun commentaire:

Enregistrer un commentaire