【发布时间】:2017-04-29 11:09:34
【问题描述】:
我只是做了非常非常基本的事情,但结果也是错误的: console.log("检查元素"+ (element(txt_LoginUsername) instanceof ElementFinder));
检查元素是否为假
但如果我使用 webstorm 的调试工具,它会给出正确的结果。
我只是在得到答案后更新问题
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));
这是结果,所以 Mirosław Zalewski 的答案是完全正确的!但是还有一个问题,ElementFinder和protractor.ElementFinder有什么区别
从“量角器”导入 ElementFinder 时查找元素并使用 ElementFinderfalse 导入量角器时的元素查找 'protractor' 并使用 protractor.ElementFindertrue
【问题讨论】:
-
Protractor 中的所有动作都是承诺,你不能像这样记录结果。在记录数据之前首先解决一个承诺。更多信息请查看here 或搜索 Stackoverflow
-
@wswebcreation 除了
element(),它返回instance of ElementFinder class。 -
@Mike 我在答案中添加了一段。它们在源代码级别上没有区别,但是 - 我不确定为什么 - JavaScript 认为它们是不同的。我认为这里有命名空间在起作用,但我无法证明这一点。如果该解释对您来说足够好,请考虑accepting my answer。如果您想了解更多信息,请考虑 asking separate question - 但请确保您发布 full reproducible example。
标签: javascript typescript protractor instanceof