-1

I just do very very basic thing but the result is also false: console.log("Check element "+ (element(txt_LoginUsername) instanceof ElementFinder) );

Check element false

But it gives the right result if I use the debug tool of webstorm.

I just update question after getting the answer

import {browser, ExpectedConditions as EC, $, $$, element, by,protractor,ElementFinder} from 'protractor'
  console.log("element find when importing ElementFinder from 'protractor' and use ElementFinder"+(element(Welcome.txt_SelectOrg) instanceof  ElementFinder));
  console.log("element find when importing protractor from 'protractor' and use protractor.ElementFinder"+(element(Welcome.txt_SelectOrg) instanceof  protractor.ElementFinder));

This is the result so the answer of Mirosław Zalewski is totally correct! But still have a question, what is the difference between ElementFinder and protractor.ElementFinder

element find when importing ElementFinder from 'protractor' and use ElementFinderfalse element find when importing protractor from 'protractor' and use protractor.ElementFindertrue

Mirek Długosz
  • 4,205
  • 3
  • 24
  • 41
Mike
  • 83
  • 8
  • All actions in Protractor are promises, you can't log the result like this. First resolve a promise before you log the data. For more info look [here](http://stackoverflow.com/questions/29331499/when-should-we-use-then-with-protractor-promise) or search Stackoverflow – wswebcreation Apr 29 '17 at 12:03
  • 1
    @wswebcreation except for `element()`, which returns [instance of ElementFinder class](http://www.protractortest.org/#/api?view=ElementFinder). – Mirek Długosz Apr 30 '17 at 22:11
  • @Mike I have added one paragraph to my answer. There is no difference between them on source code level, but - I am not exactly sure why - JavaScript thinks they are different. I think there are namespaces at play here, but I could not prove that. If that explanation is good enough for you, please consider [accepting my answer](https://meta.stackexchange.com/q/5234/312562). If you would like to learn more, consider [asking separate question](https://stackoverflow.com/help/how-to-ask) - but make sure that you post [full reproducible example](https://stackoverflow.com/help/mcve). – Mirek Długosz May 01 '17 at 13:57

1 Answers1

0

It's impossible to say for sure without more context, but I would guess that ElementFinder is not what you think it is.

Protractor does not expose its internal classes on global namespace. When I try to run code similar to yours, I get JavaScript error:

ReferenceError: ElementFinder is not defined

It does work as expected if I try:

element(txt_LoginUsername) instanceof protractor.ElementFinder

If you are not getting error, it seems that ElementFinder is defined in your code, but it is different than protractor.ElementFinder. This could be achieved by some unusual functions prototyping, such as below:

const ElementFinder = () => element('something');
ElementFinder.prototype = protractor.browser;

To verify if your ElementFinder is the same as protractor.ElementFinder, use:

ElementFinder === protractor.ElementFinder

To answer your second question ("what is the difference between ElementFinder and protractor.ElementFinder"), one would have to dive deeper into Protractor source code and see how modules and components interact together. It seems that somewhere along the way, these classes are instantiated (or maybe namespaced), making them different from JavaScript interpreter point of view, even though they have exactly the same source code.

Mirek Długosz
  • 4,205
  • 3
  • 24
  • 41
  • Thank for your smart answer. I just update my question. However, i still have a question. what is the difference between ElementFinder and protractor.ElementFinder and why my debug tool get wrong result. – Mike May 01 '17 at 03:08