How do I validate element (button) no longer present on the screen (was presented but is no longer) - Selenium Webdriver

Asked

Viewed 260 times

-1

someone can help me?

How do I validate element (button) no longer present on the screen? It was presented. I clicked and the button disappeared (expected scenario). However, I want to validate/confirm that the button no longer exists on the screen. How do I proceed?

The button is located by id "btn-two".

Using Selenium Webdriver - Java.

  • Could someone help me?

  • Hello, Estvao FPM! Please post your code, so it will be easier for someone to help you.

2 answers

0

I believe this can help you:

WebDriverWait wait = new WebDriverWait(driver, 10);

WebElement element = wait.until(ExpectedConditions.invisibilityOfElementLocated(By.id("btn-two")));

Thinking about it, just to have a comparison because I don’t have the project in Java, there is an example of Webdriverio (Javascript) that I use in my projects. It reverses the validation of wait:

$(selector).waitForExist(ms, reverse, error)

In this case the parameter reverse by default comes as false, waiting for the selector. If so true, he hopes that the selector will not bring any element.

Source - https://webdriver.io/docs/api/element/waitForExist.html

-1

I think you can do this :

assertFalse(driver.findelements(By.cssSelector("#btn-two")). size() == 0);

  • But that link from Answer that Question

  • Welcome to [en.so]! The language of the site is Portuguese, so please translate the answer (maybe you have confused with the Stack Overflow in English, but anyway...) It would also be interesting to include some explanation of your code, because answers that have only code are not ideal.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.