Having trouble locating elements within an iframe on Safari while employing Protractor

Our webpage includes an iframe that is dynamically generated using JavaScript. We are working on creating end-to-end tests for this page using Protractor. Our specific goal is to verify the presence of a div element inside the iframe. The issue we are encountering is that the test passes on Chrome on macOS Mojave, but fails on Safari 12.0.2. Interestingly, when the iframe is not generated using JS, the test successfully passes on Safari.

<html>
<head>
    <script>

function domOnLoad() {
    const rootElement = document.getElementById('root');

    const iframeElement = document.createElement('iframe');
    iframeElement.frameBorder = 0;
    iframeElement.seamless = true;
    iframeElement.scrolling = 'no';

    rootElement.appendChild(iframeElement);

    const divElement  = document.createElement('div');
    divElement.id = 'iframeRoot';

    const textElement = document.createTextNode('Test Iframe');
    divElement.appendChild(textElement);

    iframeElement.contentDocument.body.appendChild(divElement);

    console.log(rootElement);
}

    </script>
</head>
    <body onload="domOnLoad()">
        <div id="root">
        </div>
    </body>
</html>

describe('Ensuring the presence of div inside iframe', function() {
    browser.waitForAngularEnabled(false);

    it('should contain a div with ID "iframeRoot" inside the iframe', () => {
        browser.get('http://localhost:5000/examples/iframe.html/');
        browser.switchTo().frame(0);

        var divInsideIframe =  $('#iframeRoot');
        expect(divInsideIframe.isPresent()).toBeTruthy();
    });
});

Answer №1

To access the content, make sure to switch to the iframe initially.

browser.switchTo().frame('iframe');

Once you have switched to the iframe, locate the desired element.

I trust this guidance will prove beneficial for you.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Issues with clicking links using Python Selenium---Is Python Selenium failing to

I need assistance with the HTML below, as I am trying to identify and click on the a tag that contains the text MOUNT TAMALPAIS SP, CA. The href link is actually a javascript method. Here are the specifics: Code keyword = 'MOUNT TAMALPAIS SP' ...

How can I write the code to enable dragging the button for navigating to the next page?

<a draggable="true" class="user" id="leonardo" ondragstart="dragUser(this, event)" aria-selected="undefined"> IPD</a> If I want the button to navigate to the next page when dragged, what code should I write? ...

Tips for utilizing formidable with NextJS 13 API for image uploading and resolving request errors

I've been working on integrating image uploading functionality into my application. I'm currently using NextJS version 13.4.4 along with formidable@v3. However, whenever I attempt to upload an image, I encounter the following error: error TypeE ...

The text color and image size remain unchanged when I press the buttons. Perhaps there is an issue with the way I linked my JavaScript?

I'm currently working on debugging for a prework assignment at a coding school. I'm having trouble getting the buttons to function properly. Despite my limited experience, I suspect that my javascript file is not linked correctly. The javascript ...

Implementing Fullpage.js with persistent elements throughout slides

Can I keep certain elements fixed between slides? I found that the only way to accomplish this was by placing the text element outside of the slide div. <div class="section" id="section1"> <div class="intro"> <h1> ...

Is it necessary to specify the inputs property when defining an Angular @Component?

While exploring the Angular Material Button code, I came across something interesting in the @Component section - a declared inputs property. The description indicates that this is a list of class property names to data-bind as component inputs. It seems ...

The installed NPM package does not contain the necessary TypeScript compiled JS files and declaration files

I have recently released a TypeScript library on NPM. The GitHub repository's dist (Link to Repository Folder) directory includes all compiled JavaScript and d.ts files. However, after running npm i <my_package>, the resulting module contains on ...

Replacing Valid Characters in Input Field using JavaScript/jQuery Regex

I am currently developing a content management system (CMS) that allows users to customize the SEO URL of a page using a text input control. For instance, if a user is creating a gallery and wants their page to be accessible at http://www.example.com/my-1s ...

Is JSON Compatible with the Switch Statement?

Could someone help me with creating a switch statement in JSON? {"Errors":{"key1":"afkafk"},"IsValid":false,"SuccessMessage":""} I attempted to use: switch(response) { case response.Errors.key1: alert('test'); default: } However, t ...

Communication-Friendly-Component properties not properly handed over

I have integrated the react-chat-widget into my application and I am attempting to invoke a function in the base class from a custom component that is rendered by the renderCustomComponent method of the widget. Below is the code for the base class: impor ...

Can Angular retrieve the inner HTML content of an element?

Check out this demo . In this demonstration, I have created a list of "names" and I'm trying to retrieve the text of the selected element. However, whenever I click on an item from the list, I consistently get the same "innerHTML" for all users. Is ...

Tips for executing a Python function from JavaScript, receiving input from an HTML text box

Currently, I am facing an issue with passing input from an HTML text box to a JavaScript variable. Once the input is stored in the JavaScript variable, it needs to be passed to a Python function for execution. Can someone provide assistance with this pro ...

Optimizing CSS for printing by eliminating unnecessary white space with media queries

Appreciate your assistance! I'm currently working on a solution to print a specific div using CSS Media queries. When the user clicks on print, I want to hide all other elements except for the body div they chose. However, I'm facing an issue whe ...

What are the steps involved in converting a MERN application into a desktop application?

As a beginner in front-end application development, I recently created a MERN application in React with separate frontend and backend parts. Everything is working smoothly, but now I want to convert it into a desktop application that can run independently ...

Send functions from the back-end Node to the front-end Angular

Introduction I am currently working on a project that involves verifying email addresses within an API in order to grant users access to a restricted section. To accomplish this, I have developed backend node code with three functions built using Node and ...

Missing HTTP request payload

Utilizing Groovy script for executing an HTTP POST request with specified data: import groovyx.net.http.HTTPBuilder import static groovyx.net.http.ContentType.* import groovyx.net.http.ContentType import static groovyx.net.http.Method.* def http = new HT ...

Storing data securely with Firebase: Executing the task 'uploadBytes'

I am currently learning how to use Firestore for my database. I have been trying to send data from state to the database, but I keep encountering an error message that says "uploadBytes" cannot be performed on a root reference. Since I am not very familiar ...

Zoom feature available on various images

My current setup includes one main image and multiple thumbnails that can be clicked to change the main image. The issue I encountered was when using jqzoom on the main image, the zoomed image would go blank after changing. After researching on stack overf ...

When executing JavaScript code with an Ajax HTTP request, the output displayed is 2 but the

I'm currently working on a local chat application and encountering an issue where it displays an undefined result before properly showing all data. Below is the code snippet: function chatDisplay(){ if(mainchat.msg.value== ""){ a ...

What seems to be the issue with my snake game not loading properly?

I am having trouble getting something to display in my browser while working on this snake game. No matter how many times I check, I can't seem to find the mistake I made. Every time I refresh the browser, the screen remains blank. gameTime.html < ...