I'm encountering a minor (hopefully) issue. For personal reasons, I need to transition from using Protractor to Playwright. Initially, everything was smooth sailing as I migrated numerous steps without any hitches. However, I've hit a roadblock while trying to migrate Protractor's code that involves executeScript() and accessing scope.
Here is an example of what I had in Protractor:
browser.executeScript(element => $(element).scope().$ctrl.myFunction(), finder.getWebElement());
In Playwright, I attempted the following (including console.log for debugging purposes):
const elementHandle: ElementHandle | null = await this.button.elementHandle();
await this.page.evaluate(
({ element, functionName }) => {
const angularElement = (window as any).angular.element(element);
const scope = angularElement.scope();
console.log("📣📣📣", scope); // returns undefined
console.log("📣📣📣",scope.$ctrl); // also returns undefined
scope.$ctrl[myFunction]();
},
{ element: elementHandle, functionName }
);
I'm completely bewildered by this challenge. I can't seem to figure out how to make it work. Any help would be greatly appreciated! Thank you in advance!