Issue with switching iframes using WebdriverJS/ProtractortoggleClass is not functioning

For over a week now, one of my automation test cases has been stuck due to a lazy loaded iframe (the iframe is inserted into the DOM only after clicking a link). Here's an excerpt from my code:

driver.get("my url");
driver.findElement(By.linkText('REGISTER')).click();
driver.wait(function() {
    console.log("WAITING FOR EXTERNAL IFRAME");
    return driver.findElement(By.css("div#main-container > iframe")).isDisplayed();
}, 8000, "WAIT TIMEOUT!!!!");
driver.switchTo().frame(1); // The iframe has no id and I have no control
// Manipulating in the iframe

When I manually perform the steps mentioned above, I can confirm that there are two iframes on the page after clicking the "REGISTER" button. However, during automation, it consistently fails without any clear reason. I have tried looking for debugging tips for protractor and webdriverjs, but navigating through the DOM query in the REPL seems challenging due to webdriverjs' promise control flow. Any experienced advice on debugging techniques would be greatly appreciated!

Answer №1

When working with iFrames, there are three different techniques you can use:

  • driver.switchTo().frame(1);
  • driver.switchTo().default; - this will switch to the default iframe if no id is specified
  • driver.switchTo().index(0); - this will switch to the first index by default

Answer №2

When working with HTML and iframes, there are specific areas to focus on: inside the iframe and outside of it. Inside the iframe, there is a child document containing a child head and body. To interact with iframes, Element or Index methods are commonly used.

  1. Option 1

driver = browser.driver;

var iframeElement = element(by.css('path_to_iframe');

browser.switchTo().frame(iframeElement.getWebElement());

driver.findElement(by.tagName('body')).click();  

driver.findElement(by.tagName('body')).sendKeys(string);
  1. Option 2 With the first iframe, index is 0, for the second iframe index is 1, and so forth...

browser.switchTo().frame(0);

browser.switchTo().frame(1);

After finishing work within an iframe, it is important to switch back out of the iframe using:

browser.switchTo().defaultContent();

Answer №3

Working with Selenium-java is my specialty. The code snippet below has always delivered exceptional results for me.

WebDriver webDriver = new ChromeDriver();
webDriver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
webDriver.get("https://developer.autodesk.com/");

webDriver.findElement(By.id("btn_oxygen_registration")).click();

WebElement frame = webDriver.findElement(By.xpath("//iframe[contains(@src,'https://accounts.autodesk.com/register')]"));
webDriver.switchTo().frame(frame);
webDriver.findElement(By.id("firstname_str")).sendKeys("EnterUsername");

Feel free to reach out if you need more assistance.

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

Encoding multiple arrays with JSON and PHP is a powerful feature that allows

I'm working on encoding my multiple news array into JSON using PHP. Here's what my news array looks like: $news[1]["header"] = "First header"; $news[1]["content"] = "First news content"; $news[2]["header"] = "Second header"; $news[2]["content"] ...

The error message I'm encountering is: "Attempting to use the executeScript method with the argument type (String) is not compatible."

I encountered an issue stating "The method executeScript(String, Object[]) in the type JavascriptExecutor is not applicable for the arguments (String)" and I need assistance to resolve it. driver.findElement(By.id("twotabsearchtextbox")).sendKeys(new St ...

Creating cartoons from images using JavaScript

Recently, I've been experimenting with comicify for a new project. I found that by right-clicking on an image online, copying it, and then pasting it into this demo page created by the author, everything works smoothly. However, I wanted to take it a ...

Utilizing jQuery: How to pass the $this object along with additional parameters to a

Is there a way to pass the value of this along with other parameters to a function? I have attempted the following methods, but they have not been successful: function update_alt($this, my_param){ this_alt = $(this).attr('alt'); ...

Use jQuery to alter the separator to a dot and split two specified numbers

let num1 = parseFloat($('.lot2').text()); let num2 = parseFloat($('span.Price').text()); let result = num1 / num2; $('.result').text(result); }); I am trying to figure out a way to convert selected values from comma separated ...

Tips for incorporating API-provided CSS values into AngularJS expressions for stylish card customization

I am in the process of creating unique Pokemon cards that pull data from an API. My question is, how can I apply specific CSS styling to each card directly from the API, similar to how I have utilized AngularJS to render the information? So far, I have su ...

res.send No data being transmitted - in the realm of Express.js

I'm currently developing a calculator app using Express.js, but I seem to be encountering an issue with the res.send Method as I am not getting any response. My expectation is for my webpage to display the sum from the calculator.js file. Nodemon is a ...

Utilizing `v-model` on a component that contains `<script setup>` in Nuxt can cause issues with the standard `<script>` tags

Working on a Nuxt3 project, I have implemented v-model on a component. Following the guidance from Vue documentation, here is how it should be done: In the parent component: <MyInput v-model="myData" placeholder="My placeholder" /&g ...

Is there a way to populate listColumns dynamically in vue-tables-2?

Imagine you have an array of category names passed as a prop. When using vue-tables-2, how can you dynamically populate a category filter in the listColumns option? listColumns: { type: [{ id: 1, text: 'User' }, { id: 2, t ...

Interfacing Node JS with Java Web Services via SOAP

I've been attempting to connect Java web services from a Node.js module, but I'm encountering an error in the wsdl library. Below is my wsdl file: <!-- Published by JAX-WS RI (http://jax-ws.java.net). RI's version is JAX-WS RI 2.2.9-b130 ...

Send a Dictionary<String,List<String>> over to a JavaScript array

Welcome to my web service! [WebMethod] [ScriptMethod(ResponseFormat = ResponseFormat.Json)] public Dictionary<string,List<string>> GetCategorias() { var diccionario = new Dictionary<string, List<string>>(); var categoria = ...

Can the Java driver incorporate PhantomJS's onResourceRequested callback functionality?

Is there a way I can achieve the same thing, perhaps via the Java API? My goal is to prevent css files from loading in PhantomJS using the Java driver. I came across this helpful js code snippet for PhantomJS: page.onResourceRequested = function(requestD ...

Building a dynamic search feature using Ajax and PHP to transfer search results to a PHP variable or display as plain text

I designed a form that allows users to input orders with various details into the database. One of the fields in this form is labeled Client, where users have the option to either create a new client or select an existing one. To facilitate the selection ...

I am wondering about automation protractor - What is the best way to select the first value in the "job no" column of the first row in a table?

https://i.sstatic.net/nMKyp.png I am presenting three table structures on a single page. Take a look at the screenshot to see how the page will appear. ...

The luminosity of MeshBasicMaterial in Three.js

In my current setup with threejs, I am utilizing MeshBasicMaterial for lighting effects. Each element contains a simulated point light within. I have assigned a variable named color, defined as rgb(random value, random value, random value). I am looking ...

Can you retrieve a reference/pointer to a specific property of an object in JavaScript?

I am looking to generate an HTML <input> element, and then access its value property so I can update the value through that reference: var input = document.createElement('input'); var valueRef = &(input.value); *valueRef = "Hello world!" ...

A Java tutorial on dynamically skipping rows based on the group size value of the previous row

I'm encountering an issue where I cannot skip the next row number 2 if the Group size is 2 in row 1. S.No title_rcd passenger_type_rcd YoungestGroupMember GroupSize 1 MRS ADULT ADULT 2 Same Group 2 MR ADULT ADULT 2 3 MR ...

Conceal/Inactivate element when scrolling, and once scrolling comes to a halt, reveal it once more

I have been working on creating a div tag to overlay an embed tag and added some javascript to prevent users from right-clicking to download the pdf inside the embed tag (even though it may seem unnecessary, it was requested by my customer). Here is the ma ...

Fetching a destination through the post approach

Typically, we utilize window.location.href="/index.php?querystring"; in JavaScript. Is it possible to transmit the querystring via a POST method without including any form within the document? ...

Parsing text files with Highcharts

As a beginner in JavaScript and HighCharts, I am facing a simple problem that has me completely lost. My goal is to generate a scatter chart with three lines by reading data from a text file formatted like this: x y1 y2 y3 1.02 1.00 6.70 ...