Quality Testing

Quality is delighting customers

How to verify an element after the successful page loading?

How to verify an element after the successful page loading?

Views: 170

Reply to This

Replies to This Discussion

Hi,

I usually use the following method for testing, if an element is present.

public boolean isElementPresent(By element) {
try {
driver.findElement(element);
return true;
} catch (NoSuchElementException e) {
return false;
}
}

The wait time can also be configured on the WebDriver:

webDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);


I don't know any other way to do this. 

Thanks & Regards

  Hari

Thanks Guys.

There are many ways to verify this, most of the software testing company uses the following approach, first, you can check if the page is loaded there are a couple to ways like you can verify page title. Also like you asked you can look for any element on the page it could be a welcome message or anything else which is displayed every time you navigate to that page.

For e.g, You login to an application it displays a welcome message. You can assert that if that element using the most commonly used commands in verifying page elements are:

- verifyElementPresent (Returns TRUE if found)
- verifyTextPresent (Returns TRUE if found)

using these function you can build a function in utility classes & call this function whereever you need to verify if element is present before performing any actions.

    public boolean isElementPresent(String locator) {
           try {
                  driver.findElement(By.xpath((locator)));
                 return true;
            } catch (Exception e) {
           return false;
      }}

where locator = xpath of that web element.

I hope this helps.

Thanks

RSS

TTWT Magazine


Advertisement

Advertisement

Advertisement

Advertisement

© 2020   Created by Quality Testing.   Powered by

Badges  |  Report an Issue  |  Terms of Service