what does isPresent() in protractor testing actual

2020-07-24 03:24发布

问题:

whether the isPresent() provides true

  1. only when the element is present in the page

or

  1. only when the element is visible in the page (while scroll down)

If it checks only the element is present in the page, whether there is any other method to provide true only when the element is visible.Kindly provide some input.

Edit:1

I had a scrolling problem while loading a page.ie(while loading the page it will scroll down to the middle of my page)

So I am using a scroll service which will load the page correctly from the top.

The point is while using scroll service the protractor test should pass and fail when not using it.

Now when using the scroll service all the elements will be visible,I using the isPresent() which is returning true

And when not using the scroll service some elements will not be visible due to scroll down,but still I am using the same element which is not visible with the isPresent() which is also returning true.

回答1:

isPresent() returns a Promise not true or false.

If you want to check if an element is present, you actually have to look at the value that the promise resolves to:

element(anyFinder).isPresent().then(function(isPresent) {
  if ( isPresent) {
    // The element is present
  } else {
    // The element is not present
  }
});