Pages

How to wait for an element in DOM ?

presenceOf() in protractor ?

  • presenceOf() will verify the element is present in DOM or not in given time.
  • If element is not present in given time, it will throw time out error.
  • presenceOf() is just opposite of stalenessOf() in protractor.
Please check below code script:

First check the page title in DOM

presenceOf() in protractor
presenceOf() in protractor



Here we have two buttons, 1 button is present and other button is not present.

We will verify the second button which is not displaying on UI but present in DOM.
describe('Protractor - waits - presenceOf()', function () {
beforeAll(
async function () {
await browser.get("https://keeplearners.blogspot.com/2018/03/Angular-elements.html");
});
it(
'Code script to use waits - presenceOf() in protractor', async function () {
var EC = protractor.ExpectedConditions;
var dombutton = element(by.css("input#not-displaying"));
await browser.wait(EC.presenceOf(dombutton, 5000, "Element not appeared in the DOM in given time"));
await console.log("Verified element in DOM");
});
});
Output:
presenceOf() in protractor
Please comment below to feedback or ask questions.

No comments:

Post a Comment

Please comment below to feedback or ask questions.