microsoft / playwright

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
https://playwright.dev
Apache License 2.0
66.83k stars 3.67k forks source link

[Feature] Add object/embed support for frameLocators #14988

Open Pavan90 opened 2 years ago

Pavan90 commented 2 years ago

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 ?

mxschmitt commented 2 years ago

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

Pavan90 commented 2 years ago

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 commented 2 years ago

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.

Meir017 commented 2 years ago

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

Pavan90 commented 2 years ago

@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 commented 2 years ago

@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.

mxschmitt commented 2 years ago

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.

pnavalimath commented 2 years ago

@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.

mxschmitt commented 2 years ago

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

pnavalimath commented 2 years ago

@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.

Pavan90 commented 2 years ago

@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 commented 2 years ago

hello, any updates on this one ? @mxschmitt

pnavalimath commented 2 years ago

@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 commented 2 years ago

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

mxschmitt commented 2 years ago

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.

Pavan90 commented 2 years ago

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

cristinac42 commented 1 year ago

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

michalkubica commented 1 year ago

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

ncoma commented 1 year ago

I need a way to access embed elements too.

swordensen commented 1 year ago

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.

Abhi-IT-Support commented 10 months ago

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…/>,