Im trying the code below but it seems it does not work... Can someone show me the best way to do this?
public void verifyThatCommentDeleted(final String text) throws Exception { new WebDriverWait(driver, 5).until(new ExpectedCondition<Boolean>() { @Override public Boolean apply(WebDriver input) { try { input.findElement(By.xpath(String.format( Locators.CHECK_TEXT_IN_FIRST_STATUS_BOX, text))); return false; } catch (NoSuchElementException e) { return true; } } }); }
To make sure that an element is present you can do the following: driver. findElements(By.id("id")); That will return an array, if that array size is > 0 then the element/s is present.
isDisplayed() is the method used to verify a presence of a web element within the webpage. The method returns a “true” value if the specified web element is present on the web page and a “false” value if the web element is not present on the web page.
First Solution: Try to write unique XPATH that matches with a single element only. Second Solution: Use Explicit wait feature of Selenium and wait till the element is not visible. Once it is visible then you can perform your operations.
Instead of doing findElement, do findElements and check the length of the returned elements is 0. This is how I'm doing using WebdriverJS and I expect the same will work in Java
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With