Tuesday, 15 July 2014

java - How to wait until an element no longer exists in Selenium -


I am testing a UI in which the user clicks the delete button and a table entry disappears like, I want to be able to check that table entry no longer exists.

I've tried Expected Conditions.not () to convert ExpectedConditions.presenceOfElementLocated () , hopefully it will mean "hopefully That there is no specific element "My code is:

  Browser. Navigate (). ("Http://stackoverflow.com"); New WebDriverWait (Browser, 1). Unless (required conditions. (Expected conditions. Presentations published (By.id ("foo"))); However, I found out that due to this, I am saying because of the  timeout xpcation  a  noSuchElementException  element that is "foo "Does not exist. Of course, there is no such element that I want, but I do not want any exception to throw me. 

How can I wait until an element exists? I like an example which does not rely on catching an exception if all possible (as I think, exceptions should be thrown for extraordinary behavior).

You can also use -

  New WebDriverWait (driver) , 10). Unless (ExpectedConditions.invisibilityOfElementLocated (locator));  

If you go through its source then you can see that both NoSuchElementException and staleElementReferenceException are handled.

  / ** * There is an expectation to see if an element is either invisible or not * exists at the DOM * * @ Param Locator used Element * / Public Fixed Candidate Conditions & lt ; Boolean & gt; InvisibilityOfElementLocated (final by locator) {New casual withdrawal return & lieutenant; Boolean & gt; () {@ Override Public Boolean Apply (WebDrive Driver) {try {return! (FindElement (locator, driver) .isDisplayed ()); } Hold (KnowledgeApplement E) {// Return is true because the element is not present in the DOM // Check block block if the element exists but is invisible. Back true; } Hold (StaleElementReferenceException E) {// Return is true because the stale element reference means that the element // is no longer visible; back to true; }}  

No comments:

Post a Comment