Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Protractor waiting for element to be in DOM

I have been having some trouble using Protractor. I have a really weird ui-router state where its hard to go off of other elements to start working with the page. Is there any way to tell protractor to wait until an element finally appears in the DOM? Not visible/displayed, but actually created? I keep trying to use wait for the element but it is clearly not available to be selected.

browser.driver.wait(function () {     return elem.isDisplayed(); }); 
like image 289
Tyler Pflueger Avatar asked May 13 '15 03:05

Tyler Pflueger


People also ask

How do you wait for an element in a Protractor?

wait together with the presenceOf ExpectedCondition: var until = protractor. ExpectedConditions; browser.

How to use browser wait in Protractor?

You can use then() to have a correct order in this case: beforeEach(function() { browser. wait(function() { console. log('1 - BeforeEach WAIT'); return true; }).

How do you add implicit wait in Protractor?

Add it in the onPrepare() function of your protractor's conf. js file. The reason to add implicitlyWait() there is because implicit wait is the default time that protractor waits before passing or throwing an error for an action.

How to wait for an element in protractor?

19 Protractor has included ExpectedConditionfor explicit wait which lets you wait for the element for certain period of time. You should be able to do the following: var EC = protractor.ExpectedConditions; browser.driver.wait(function () { browser.wait(EC.visibilityOf(elem), 10000); return elem; });

How to check if an element is present in Dom in protractor?

In protractor, there are multiple ways to check if an element is present in the DOM. Let us see them with examples :-. In previous article we have discussed about locators to find the elements on web page in protractor. 1. element(locator).isPresent() Checks whether the element is present on the page.

How to find the elements on web page in protractor?

In previous article we have discussed about locators to find the elements on web page in protractor. 1. element(locator).isPresent() Checks whether the element is present on the page. It returns true if the element is present on the page or returns false. NOTE: - It only check for element present in the DOM while it's not displayed.

How to wait for element for certain period of time?

Protractor has included ExpectedConditionfor explicit wait which lets you wait for the element for certain period of time. You should be able to do the following: var EC = protractor.ExpectedConditions; browser.driver.wait(function () { browser.wait(EC.visibilityOf(elem), 10000); return elem; });


2 Answers

You should be able to use browser.wait together with the presenceOf ExpectedCondition:

var until = protractor.ExpectedConditions; browser.wait(until.presenceOf(elem), 5000, 'Element taking too long to appear in the DOM'); 
like image 179
Michal Charemza Avatar answered Sep 18 '22 17:09

Michal Charemza


Protractor has included ExpectedCondition for explicit wait which lets you wait for the element for certain period of time. You should be able to do the following:

var EC = protractor.ExpectedConditions;  browser.driver.wait(function () {     browser.wait(EC.visibilityOf(elem), 10000);     return elem; }); 
like image 23
Saifur Avatar answered Sep 18 '22 17:09

Saifur