akcasoy
akcasoy

Reputation: 7215

Protractor: How to get Element object from ElementFinder

I have an elementFinder object like this:

this.spinnerContainer = element(by.id('spinnerContainer'));

And i want to run a script in browser with executeScript, where i need the spinnerContainer. But getComputedStyle expects an Element object, not an ElementFinder.

browser.executeScript('return window.getComputedStyle(' + spinnerContainerElm + ', \':after\').content;').then((content) => {
   expect(content).to.eventually.equal('none').and.notify(callback);
});

How can i reuse my spinnerContainer (from type ElementFinder) in an executeScript call?

Upvotes: 0

Views: 276

Answers (1)

DublinDev
DublinDev

Reputation: 2348

try this:

browser.executeScript('return window.getComputedStyle(arguments[0], \':after\').content;',spinnerContainerElm).then((content) => {
   expect(content).to.eventually.equal('none').and.notify(callback);
});

The executeScript function requires two parameters, the script to run and any arguments for that script (being the element in this case) See documentation

After thinking about this again the two parameter may not actually always be required but the above approach should still work for you.

Upvotes: 1

Related Questions