playwright icon indicating copy to clipboard operation
playwright copied to clipboard

[Feature] Add object/embed support for frameLocators

Open Pavan90 opened this issue 2 years ago • 22 comments

Hello, I am using html object element (https://developer.mozilla.org/en-US/docs/Web/HTML/Element/object) and trying to access it using page.frameLocators but receiving the below errors. Screen Shot 2022-06-20 at 11 36 26 AM

My assumption is that frameLocator only works for html element "iframe" but Is there anyway I can able to find a workaround to access element ?

Pavan90 avatar Jun 20 '22 16:06 Pavan90

Could you share the HTML with us or a site which has this element? Is it a PDF by any chance?

mxschmitt avatar Jun 20 '22 18:06 mxschmitt

this is the project that i am working on which i cannot share the code. Basically, playwright is not recognizing element as an alternate to iframe and also this is not a pdf. Its a straight up html element which performs as equal to iframe but only little different than iframe.

Pavan90 avatar Jun 20 '22 19:06 Pavan90

You can try this: I created a sample project in stackblitz with object tag. https://stackblitz.com/edit/angular-ivy-evxcng?file=src/app/app.component.html Please do let me know if you can able to access object element and perform any actions.

Pavan90 avatar Jun 20 '22 19:06 Pavan90

@mxschmitt I think this applies to https://developer.mozilla.org/en-US/docs/Web/HTML/Element/embed elements as well

Meir017 avatar Jun 22 '22 19:06 Meir017

@mxschmitt looks like you have merged your PR for object support. Appreciate your efforts to add this element to playwright framelocators. Could you please let me know in which release version does this code will be added ?

Pavan90 avatar Jun 22 '22 20:06 Pavan90

@mxschmitt I have tried installing alpha version 1.24.0-alpha-jun-23-2022 but I guess your PR isn't included in that release.

Pavan90 avatar Jun 23 '22 14:06 Pavan90

I did not merge the PR, it was a proposal and we decided for now to hold it off and wait more users to run into that request. Thats why I marked it as p3 which is a feature-request.

mxschmitt avatar Jun 23 '22 14:06 mxschmitt

@mxschmitt great thanks for making this quick change I was excited that #15030 is going to be merged to one of the release. Looking at the playwright features and trends, I wanted to propose using playwright over cypress. With some workarounds in cypress we are at least able to work on object elements. Thought Cypress is still not a perfect solution for our app automation.

We have to leave with object elements in our application because it does take data property which holds important values to pass it to child apps. Moving to iFrames is not feasible in our application.

Hence only hope is to looking forward for "object" element support in our automation tools. It would be great if you could help us by merging this to one of the nearest release branch.

pnavalimath avatar Jun 23 '22 15:06 pnavalimath

Upvote the issue at the top and then we'll most likely considering adding it!

mxschmitt avatar Jun 23 '22 15:06 mxschmitt

@mxschmitt I have done my part of 👍 I'm sure you would also be equally eager to get it merged, especially when you know that it helps community. Looking forward to hear positive news at the earliest otherwise anyway community would seek help at some other tool or community.

pnavalimath avatar Jun 23 '22 18:06 pnavalimath

@mxschmitt I believe we got more than enough votes to add this feature to upcoming release and i really appreciate everyone for upvoting this request :)

Pavan90 avatar Jun 27 '22 15:06 Pavan90

hello, any updates on this one ? @mxschmitt

Pavan90 avatar Jul 19 '22 19:07 Pavan90

@mxschmitt any updates on this feature request or any tentative dates for release? I'm wondering when the fix is ready and people have expressed interest, what is holding from merging to master branch or releasing it?

I was wondering why people are not adopting playwright fast, over Cypress. Looks like I'm getting some answer now looking at this open issue for more than a month 👎

pnavalimath avatar Jul 21 '22 13:07 pnavalimath

@mxschmitt I was wondering if we can we have any hope of having it any release 🤔

pnavalimath avatar Aug 02 '22 11:08 pnavalimath

We usually don't provide any eta's on feature requests, based on upvotes we make decisions which features we put in the upcoming release.

mxschmitt avatar Aug 02 '22 12:08 mxschmitt

Hello @mxschmitt, Just wondering if there are any latest updates on this request ?

Pavan90 avatar Aug 12 '22 15:08 Pavan90

Hi, I have the same problem with the embed elements. Are there any updates on this request?

cristinac42 avatar Nov 15 '22 13:11 cristinac42

I am very much looking forward to the support of "embed" elements, too.

michalkubica avatar Apr 25 '23 07:04 michalkubica

I need a way to access embed elements too.

ncoma avatar Sep 13 '23 22:09 ncoma

Since this issue seems to be pending community need I wanted to add my use case: I simply want to write tests for a legacy application that still uses <object> instead of <iframe>. I believe this is because the app was written before SPAs were mainstream.

Anyways, here's the patch-package I made based on @mxschmitt 's PR

playwright-core+1.38.1.patch

index cf2aaf5..b17d7b8 100644
--- a/node_modules/playwright-core/lib/server/dom.js
+++ b/node_modules/playwright-core/lib/server/dom.js
@@ -159,7 +159,7 @@ class ElementHandle extends js.JSHandle {
     return null;
   }
   async isIframeElement() {
-    return this.evaluateInUtility(([injected, node]) => node && (node.nodeName === 'IFRAME' || node.nodeName === 'FRAME'), {});
+    return this.evaluateInUtility(([injected, node]) => node && (node.nodeName === 'IFRAME' || node.nodeName === 'FRAME' || node.nodeName === 'OBJECT'), {});
   }
   async contentFrame() {
     const isFrameElement = throwRetargetableDOMError(await this.isIframeElement());
diff --git a/node_modules/playwright-core/lib/server/frameSelectors.js b/node_modules/playwright-core/lib/server/frameSelectors.js
index b4bc820..d7996c3 100644
--- a/node_modules/playwright-core/lib/server/frameSelectors.js
+++ b/node_modules/playwright-core/lib/server/frameSelectors.js
@@ -126,7 +126,8 @@ class FrameSelectors {
         selectorString
       }) => {
         const element = injected.querySelector(info.parsed, scope || document, info.strict);
-        if (element && element.nodeName !== 'IFRAME' && element.nodeName !== 'FRAME') throw injected.createStacklessError(`Selector "${selectorString}" resolved to ${injected.previewNode(element)}, <iframe> was expected`);
+        console.log({NODENAME: element.nodeName});
+        if (element && element.nodeName !== 'IFRAME' && element.nodeName !== 'FRAME' && element.nodeName !== 'OBJECT') throw injected.createStacklessError(`Selector "${selectorString}" resolved to ${injected.previewNode(element)}, <iframe> was expected instead of ${element.nodeName}`);
         return element;
       }, {
         info,

these changes work for me and I am able to navigate the object's html tree as I would expect.

swordensen avatar Oct 12 '23 23:10 swordensen

Hi @mxschmitt, Any update on embed tag testing using playwright? I am facing one issue related to embed tag. Actually, I have suggested my team to use playwright instead of cypress. but we are facing one issue with current embed tag testing. Playwright does not support embed testing. here are the error details. Error: locator.click: Error: Selector "embed" resolved to <embed width="100%" height="100%" src="https://my.share…/>,

please let me know if embed tag testing is possible with playwright tool? Thanks.

Abhi-IT-Support avatar Dec 29 '23 14:12 Abhi-IT-Support

Hello @mxschmitt

We have also been evaluating Playwright and their is a huge barrier we are facing currently to adopt Playwright as a primary tool for automation since Playwright is not able to identify embed tags in the SUT . ( captured here : https://github.com/microsoft/playwright/issues/28926 )

As a result internally there are allready proposals to evaluate other automation tools ( other than Playwright ) which support inherent identification of embed tags , since there is no clear visibility when this feature will be available in Playwright .

I beleive having the support for embed tags added in Playwright right away , can help boost popularity & hence community of Playwright & avoid users switching to other Automation tools ( able to identify embed tags ) without even spending time raising issues here & hence cannot be tracked .

**Thus to sum it up : **It can be very helpful for the present & potential Playwright community members to have this feature of identification of embed tags , made available asap in next release of Playwright , while holding this feature back will only create a disadvantage for Playwright & lose out on early adopters of Playwright to other competing automation tools ****

Thanks & Best Regards

abhiam1 avatar Jan 24 '24 17:01 abhiam1

Wanted to say, this is also a blocker for my team as this issue hasn't had activity in a while. Would be great to see the fix go in!

mhogara avatar Jul 26 '24 14:07 mhogara