How to find the element that displays and hides with in 2 seconds in selenium webdriver?



  • I am automating a site in which there is a section to create forums. Every time I create a forum it displays message as forums created and hides after 1 section. I have to check the displayed message, But many times it throws exception as "Element is not usable" @FindBy(id="create_forums") private WebElementFacade forums; @FindBy(id="forum_message") private WebElementFacade message; forums.click(); assertThat(message.getText(),equals("expected"); //here the element message throws "Element is not usable exception" as it hides with in two seconds.. public String getMessage() { String messagetxt = ""; try { if (Message.isDisplayed()) { messagetxt = Message.getText(); } else { messagetext = ((JavascriptExecutor) getDriver()).executeScript( "return arguments[0].innerHTML", Message).toString(); logger.info("message"+messagetxt); } } catch(NoSuchElementException ne) { logger.info("status message not displayed..... checking from the page source"+ nsee); } return messagetxt; } How can I find the element or at least handle the exception



  • How to Pause a WebPage to get a locater There are times when there is something on a page that we need to get the WebDriver locater for, but the object disappears too quickly to inspect it. Here is how to get it: Open Chrome (I believe this only works in Chrome) Go to the desired URL Open the Development Tools (Ctrl+Shift+I)     a. For this case, I like to have the Development Tool window as a new Window Do the action needed to get to your tricky element As soon as the element is in the state you wish, hit F8     a. This will pause the DOM.     b. You can then expect the element     c. There is a icon on the page to resume     d. NOTE: This takes a ton of memory, your system might slow way down. Work fast and then un-pause.



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2