Element is not locatable after page has been refreshed in Selenium

I attempted to create a selenium test that verifies if navigating from one page to another occurs successfully when clicking on buttons. Initially, the test checks if clicking a button on the old page leads to navigation to a new page. Then, it verifies if clicking a button on the new page navigates back to the old page as expected.

Upon executing the test, I encountered an issue where the selenium automation is able to click on the button on the first page and confirm the presence of the button element on the new page. However, when trying to click on the button element on the second page and verifying if the button on the first page reappears, the test fails to locate the button element on the initial page despite using the same button for navigation previously. Even though the first page appears to be loaded, attempts to wait using different statements such as 'waitForPageToLoad()', 'waitForTextPresent("", "text on first page")', or 'waitForElementPresent("" , //path to first button element)' were unsuccessful.

No matter which waiting statement was used, the automation still could not find the button element even though it was identified during the initial loading of the page.

Answer №1

I had a moment of clarity when I noticed that the second time I refreshed the initial page, I needed to use driver.switchTo().frame(driver.findElement(By.xpath("path to iframe")) first because the application was located within an iframe. This way, it wouldn't be able to locate the elements on the second attempt unless I switched to the iframe beforehand.

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

I'm curious about how to use nightwatch.js to target a dynamically generated element with a dynamic value

I'm facing an issue with identifying dynamically generated elements in a list box using JQuery or some other scripting language. My goal is to select a specific market value that is passed dynamically. The code I've currently implemented is as fo ...

Is there a built-in method that can be used to transform JSON into URL parameters?

Is there a built-in function in JavaScript or the JSON object to convert a JSON object to URL form like: "parameter=12&asd=1"? This is how I have achieved it: var data = { 'action':'actualiza_resultado', ...

Creating polygon surfaces from points in THREE.js

I'm struggling to find the solution, even though I am working on the 3D Graphics course on Udacity that utilizes three.js. The task at hand is to create a 3D mesh and while I have successfully generated the vertices, I am facing difficulties with gene ...

Remove image files from a directory with jQuery without relying on PHP or AJAX

Did you know that JQuery code is capable of executing unlink operations like PHP without using AJAX or a PHP file? For instance, if you wish to delete or unlink the file "aaa.jpg" located in the folder www.myproject.com/images/, you can achieve this by s ...

Creating a mongoDB query that matches elements in an array of subdocuments with elements in a Typescript Array

In my database, I have stored various Events using mongoDB. Each event comes with multiple fields, including an array of genres, which consists of subdocuments like {genre and subGenre}. For instance, an event could be classified as {genre: "music", subGe ...

Steps to indicate a selected check column in a grid

I am working with a grid that has a check column, and I need to programmatically mark the checkbox. This is how the check column is coded: columns: { items:[ { itemId: 'checkColumn', xtype: 'selectallche ...

Generating a 3D face using three coordinates in Three.js

Currently, I have implemented code that allows me to load, render, and display a STL object using Vue.js and Three.js. My goal now is to replace the currently selected plane with a new face. I've managed to extract the 3 vertices of the clicked-on fac ...

Creating a web form with the ability to select multiple images using Javascript

Currently, I am in the process of developing an HTML form that enables users to select an image, a URL, and text that will be inserted as a <li> into a webpage. However, I am facing an issue where I want users to create multiple <li> per input. ...

I am attempting to retrieve the XPath for a dropdown menu

I'm currently working on extracting the XPath for a dropdown field that I can incorporate into my Python code using Webdriver. The HTML contains two dropdown fields. I specifically need to pinpoint the dropdown that includes options such as Person Nam ...

Ways to boost an array index in JavaScript

I recently developed a JavaScript function that involves defining an array and then appending the values of that array to an HTML table. However, I am facing an issue with increasing the array index dynamically. <script src="https://cdnjs.cloudflare. ...

Even with employing Cors alongside Axios, I continue to encounter the following issue: The requested resource does not have the 'Access-Control-Allow-Origin' header

When working with a MEAN stack app, I had no issues with CORS. However, upon transitioning to the MERN stack, I encountered an error related to CORS despite having it implemented in the backend: Access to XMLHttpRequest at 'http://localhost:5000/api/ ...

React State Property that looks at properties within its own scope

Can a property within the React state object reference its own properties? Consider the example below: this.state = { currentTotal: 30, columnLength: Math.ceil(this.currentTotal / 3), // Resulting in NaN. } ...

Is it possible to customize the Toolbar in react-data-grid by adding your own components?

I have been working with the react-data-grid and I'm almost done with it. The filters button is already displaying in the Toolbar, but now I need to add another button that will affect all selected items in the table. I want to place this new button o ...

Pattern for validating mobile numbers with extensions using regular expressions

I am struggling to combine multiple separate regex validations into one for my mobile number validation requirements. The criteria include validating mobile numbers with a country code or starting with 00, as well as checking if they contain an extension n ...

"Having trouble with sound in react-native-sound while playing audio on an Android AVD? Discover the solution to fix this

react-native-sound I attempted to manually configure react-native-sound but I am unable to hear any sound. The file was loaded successfully. The audio is playing, but the volume is not audible on Android AVD with react-native-sound. ...

What steps do I need to take to ensure my app shows an error message instead of the broken image link?

function getDogImage(breed) { fetch(`https://dog.ceo/api/breed/${breed}/images/random`) .then(response => response.json()) .then(responseJson => displayResults(responseJson)) .catch(error => alert('Something went wrong. T ...

Enhancing choices for a select tag that is generated dynamically

I am encountering challenges while adding options to the dynamically generated select tags using jQuery. The options are fetched from a database, and I want to display all these options for each dynamically created select tag. Could you please point out w ...

Is it possible for a chrome extension to allow only specific third-party cookies and storage to be

My Chrome extension inserts an iframe from foo.com into bar.com, creating a situation where bar.com now includes a foo.com iframe. However, I have observed that this iframe encounters difficulties when attempting to write to localStorage if the user has ...

Is there a way to implement prototype inheritance without contaminating an object's prototype with unnecessary methods and properties?

I prefer not to clutter the object prototype with all my library's methods. My goal is to keep them hidden inside a namespace property. When attempting to access an object property, if it is undefined, the script will search through the prototype cha ...

What is the best way to utilize the react hook useEffect just once in my scenario?

After looking into it, I realized that my question may seem like a duplicate at first glance, but upon further inspection, I found that it is not. I have come across many questions with the same title but different cases. The issue I am facing is that I h ...