Difference between element(…) and element(…).getWebElement() in Protractor

六月ゝ 毕业季﹏ 提交于 2021-02-07 06:14:01

问题


  • Why we need element(...).getWebElement() over element(...) when both works exactly the same
  • Why two APIs for the same functionality

回答1:


Protractor is a convenient wrapper around WebDriverJS - javascript selenium bindings.

  • element(...) would result into an ElementFinder instance introduced in Protractor
  • element(...).getWebElement() would result into a WebElement instance from WebDriverJS. Basically, this gives you access to the pure "bare-metal" WebElement.

The most common use-case for using getWebElement() is when you need to pass an ElementFinder as a script argument - currently you have to call getWebElement() for this to work:

var elm = element(by.id("myid")); 
browser.executeScript("arguments[0].click()", elm.getWebElement());

There is an open feature-request to be able to pass ElementFinder directly:

browser.executeScript("arguments[0].click()", elm);  // not gonna work as of now


来源:https://stackoverflow.com/questions/39026997/difference-between-element-and-element-getwebelement-in-protractor

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