Is there a way to determine if a new DOM element has been appended using Selenium in Java or JavaScript?

When using selenium-java, I encountered an issue where after switching to a new frame, a new DOM was appended on top of the existing one. However, when I tried to locate elements within the appended DOM using the findelement method with the xpath, it threw a staleelementnoreference exception.

Is there a way in selenium/java/javascript to identify if a new DOM has been appended or not? I tried using explicit wait to handle the staleelementexception, but it didn't work in IntelliJ (2018.3) while it did work in Eclipse.

Answer №1

In the scenario where you are using Selenium with an iFrame and there's just one iframe present:

Prior to executing findElement(), you need to switch to the new frame.

HERE'S WHAT YOU SHOULD DO

driver.switchTo().frame(driver.findElements(By.tagName("iframe")[0]));

If you want to go back to the main page:

driver.switchTo().defaultContent();

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

Retrieve the identifier of the selected hyperlink

Is there a way to retrieve the ID of a clicked link using jQuery? I am getting an Undefined result, why is that? test = function(e) { alert($(e).attr('id')); return false; } $('.bleu').click(test) <script src="https://ajax ...

Arranging array elements according to the values in another array

I am working with an array of selections: var selections = ( JSON.stringify($('#approval').select2('data')) ); var selections = JSON.parse("[" + selections + "]"); When I use console.log with selections, the output is: https://i. ...

What causes the difference in behavior between using setInterval() with a named function as an argument versus using an anonymous function?

I can't seem to figure out why using the function name in setInterval is causing issues, while passing an anonymous function works perfectly fine. In the example that's not working (it's logging NaN to the console and before the first call, ...

Adding the "input-invalid" class to the input doesn't take effect until I click outside of the input field

When the zipcode field is updated, an ajax call is made. If there are no zipcodes available, I want to mark it as invalid by adding the "input-invalid" class. However, the red border validation only appears when clicking outside of the input field. Is ther ...

The issue of texpress-session failing to set a cookie in a React application arises when the app is deployed

I'm encountering an issue where I can't establish session cookies in the browser for my MERN stack application. Everything works fine when both the express server and the react front end are running locally, but the problem arises after deploying ...

Updating a behavior object array in Angular 5 by appending data to the end

After creating a service to share data across my entire application, I'm wondering if it's possible to append new data to an array within the userDataSource. Here is how the service looks: user.service userDataSource = BehaviorSubject<Array& ...

The Apollo Client mutation input type is missing data

Currently, I am working with Apollo-client and facing an issue while making a mutation on the client. It seems that when I perform my mutation, the data being passed to the server becomes void. Below is my mutation type: type: recipeType, args:{ ...

Is it possible to observe a shift in the current locale of internationalization (i18n)?

Is there a way to trigger a function when the language/locale changes with i18n? Can I achieve this using Vuex, or is there a specific method in vue-i18n to accomplish this? ...

What could be causing the directives module to not get properly incorporated into the Angular app module?

I am currently in the process of learning Angular and have come across some challenges with module resolution. In js/directives/directives.js, I have a directive scoped within a directives module: angular.module("directives").directive("selectList", funct ...

In what scenarios does Element.getClientRects() provide a collection of multiple objects as a return value?

Every time I use Element.getClientRects(), it always gives me a collection containing just one DOMRect object. Under what circumstances does Element.getClientRects() return a collection with multiple DOMRect objects? function handleClick() { console. ...

Issue: The write() function requires the argument to be a string, not bytes, in UTF-16 format

Recently, I've been running test cases using Selenium and Python, aiming to create HTML Test reports for better analysis. In my quest, I stumbled upon a promising resource that claims to automate this process at . It seems quite efficient, but unfortu ...

a guide on retrieving FormData objects in PHP

Hey everyone, I have a question regarding a sample code snippet I posted here. In this code, I am successfully uploading a file using Ajax JQuery. However, I am struggling to figure out how to read the content of the uploaded file in my PHP code. Can anyon ...

Do we really need to implement ajax in this code snippet?

In my scenario, I have two JSP files named test1.jsp and test2.jsp. The flow of my program goes like this: I need to retrieve data from a textbox in test1.jsp, but the Ajax call is initiated from a different page. My objective is to receive the controller ...

What is the best way to pass a variable in an AJAX function call when making a POST request?

I am facing an issue with sending a variable through an ajax function. The scenario is as follows: <a href="next.php" onclick="sendajax()">reload</a> I need to send this variable via the POST method in my php page: <script> fu ...

reach an agreement on the implementation of infinite scrolling when navigating backwards

I'm looking to create a feature where clicking the back button will return me to the same position on the page. A great example of this is on . If you scroll down, click on a product, and then go back from the product page, you'll be taken back t ...

Tips on inserting an image within a div that is created dynamically

I'm currently working on creating dynamic div elements in my JavaScript using the code below: var div = $('<div id="a1"></div>').html("<font color=green>This is a demo</font>"); I am struggling to figure out how to ...

Remove objects from an array if they share identical key values

I'm having trouble getting this to work. I have an array of objects that looks like this: let myCities = [ { value: 'Barcelona', code: 02342837492482347 }, { value: 'Rome', code: 28282716171819 }, { v ...

Angular - attach event listener to Bootstrap dropdown menu

Looking to add an overlay on the screen behind a menu when it's expanded, but unsure of how to do this with Bootstrap. Any suggestions on listening for when the menu expands? Here is my current menu code: <link rel="stylesheet" href="https://st ...

Is it possible to use function declaration and function expression interchangeably?

As I dive into learning about functions in Javascript, one thing that's causing confusion for me is the difference between function declaration and function expression. For example, if we take a look at this code snippet: function callFunction(fn) { ...

The X-frame-Options HTTP response header is ineffective

I've been attempting to implement the X-Frame-Options response header in my application by configuring it on my express server. Utilizing the helmet npm package, I've applied the following code snippet: const express = require("express" ...