Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

  • Why we need element(...).getWebElement() over element(...) when both works exactly the same
  • Why two APIs for the same functionality
like image 580
Prashanth Sams Avatar asked Aug 18 '16 20:08

Prashanth Sams


People also ask

What is getWebElement?

getWebElement() would result into a WebElement instance from WebDriverJS . Basically, this gives you access to the pure "bare-metal" WebElement .

What is element in Protractor?

In protractor, the single web element belongs to type ElementFinder. The ElementFinder can be treated as a WebElement for most purposes, in particular, you may perform actions (i.e. click, getText) on them as you would a WebElement.

What is a element Finder?

ElementFinder can be used to build a chain of locators that is used to find an element. An ElementFinder does not actually attempt to find the element until an action is called, which means they can be set up in helper files before the page is available.

How do you declare a WebElement in protractor?

import { browser, element, by} from 'protractor' import { protractor } from 'protractor/built/ptor'; describe('Protractor Typescript Demo', function() { browser. ignoreSynchronization = true; it('click operation', function() { browser. get('https://google.com/'); browser. sleep(1000) element(by.name('q')).

How to get the element of type webelement in protractor?

GetWebElement() function in Protractor. Purpose: The element() returns value type of ElementFinder. However, if required we can use the getWebElement() function to get the element of type WebElement. Syntax: element(locator).getWebElement(): WebElementPromise; Returns: This function returns the value of type WebElementPromise. Code Example:

What is the difference between protractor and elementfinder?

When we use element (locator)) the protractor returns element of type ElementFinder, as discussed earlier ElementFinder is a protractor wrapper. There might be some instance where one may need pure or raw web element which selenium returns.

What is the difference between elementfinder and getwebelement ()?

Note: ElementFinder can be chained with element array finder which will be covered in the next article. Purpose: The element () returns value type of ElementFinder. However, if required we can use the getWebElement () function to get the element of type WebElement. What is the difference between Element (locator) and GetWebElement ()?

What is protractor and selenium in web design?

With the help of protractor and selenium, these elements are uniquely identified. Each web element is associated with the property such as class, tags, id or attributes which uniquely identifies that element. What is ElementFinder in Protractor? In protractor, the single web element belongs to type ElementFinder.


Video Answer


1 Answers

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
like image 70
alecxe Avatar answered Oct 23 '22 03:10

alecxe