what does isPresent() in protractor testing actually do?

十年热恋 提交于 2019-12-22 01:14:28

问题


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
  }
});


来源:https://stackoverflow.com/questions/34811569/what-does-ispresent-in-protractor-testing-actually-do

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!