Issue with locating element in iframe using Selenium and Chromedriver: Element not found

Having some trouble working with Selenium/Chromedriver via Protractor. I try to switch to an iframe, wait for the contents to load, and then manipulate elements inside it. However, the program doesn't seem to recognize when the content has loaded.

browser.driver.switchTo().frame("myView");

browser.driver.wait(function() {
    return browser.driver.isElementPresent(by.id("myDiv"))
        .then(function (isPresent) {
            return isPresent;
        });
}, 20000, "Taking too long to load!");

The element myDiv should be present within 20 seconds, but the wait() function times out.

I also attempted using browser.driver.findElement(), with no success.

I made sure to update to Chromedriver 2.21 as well.

Any suggestions on what else could be causing this issue?

Update: Upon checking the error log, here's what is displayed...

   Message:
     Error: Taking too long to load!
 Wait timed out after 20069ms
   Stacktrace:
     Error: Taking too long to load!
Wait timed out after 20069ms
==== async task ====
Taking too long to load!
    at /Users/me/Documents/My-Test/specs/myWorkflow.js:82:20
==== async task ====
    at [object Object].<anonymous> (/Users/me/Documents/My-Test/specs/myWorkflow.js:79:14)
==== async task ====
Asynchronous test function: it()
Error
    at [object Object].<anonymous> (/Users/me/Documents/My-Test/specs/myWorkflow.js:7:5)
    at Object.<anonymous> (/Users/me/Documents/My-Test/specs/myWorkflow.js:5:1)

Answer №1

One method I've used to work around similar issues is by incorporating a sleep statement instead of relying on a wait loop. In my experience with C#, I typically utilize Thread.Sleep(20000); for a 20-second delay. However, the majority of my waits usually fall within the range of 1 to 5 seconds.

To clarify further: I recommend eliminating the loop that is currently being utilized for element validation and instead opting for a straightforward sleep command followed by interaction with the element.

When using Selenium in conjunction with C#, I have successfully implemented the following code snippet to insert a set delay while waiting for an element to fully load before proceeding with clicking it. While the specific element in this example is a link, this approach can be applied to any type of element within your automation workflow:

// Add a brief sleep time to allow UX to load
Thread.Sleep(3000);

// Proceed to open the new form
By newButton = By.XPath("/dummy/xpath");
IWebElement button = driver.FindElement(newButton);
button.Click();

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

JavaScript: Retrieve an array that is both unique and sorted

I have an array that contains duplicate items. My goal is to filter out these duplicates and return only the unique items, sorted based on their frequency of occurrence in the initial array. const initialArr = [ { id: 1 }, { id: 1 }, ...

Issues with anchor tag click event in Firefox browser not functioning as expected

I have encountered an issue while trying to create an anchor tag in a TypeScript file. When clicking on this button, the anchor tag should be created. This functionality is working correctly in Chrome and IE, however, it seems to be not working in Firefo ...

Guide for Extracting a String in JavaScript that Includes Numerals for Color Code Alteration, Resulting in Formats like 32m+ or 31m-

Attempting to create a Firebase cloud function in JavaScript that sends email notifications for any changes in the Firebase remote config. Upon each remote config change, the string received is in the following format: { parameters: { [32m+ newer_value: ...

"Encountered an issue with the validation upon clicking the submit

Here is my sample code snippet <form action="next2.php" method="post" name="next2" id="next2" onsubmit="return submitForm();"> Here is the JavaScript function I am using <script type="text/javascript"> function submitForm() { var ...

Using Selenium with Python to Locate Fields Generated Dynamically

Hello everyone, I'm a beginner in this field and I've been learning for 2 days now. I am facing an issue with a learning management system where there is an icon (a plus mark) that adds a form field when clicked. The objective is to click the ic ...

Tips for setting up a due date alert system

As a novice, I'm attempting to develop a function that can switch between texts based on a set due date. The text displayed will change to "Expired" once the due date is reached, and it will remain as "Active" if the date hasn't been reached yet. ...

Is there a way to halt the execution of my code until the papaparse operation is complete?

Before moving on to looping through the list, I want papaparse to finish populating it. The issue is that papaparse completes after the loop in my code, causing the loop to run over an empty list. Here's how my code looks: const csvData=[]; papa.pars ...

Getting a double integer value from an Excel sheet using Selenium

I have been working on a code to extract values from an Excel sheet. The values can be strings, dates, or long integers. While I am able to correctly extract strings and dates with the below code, I am facing an issue with long integer values. Instead of ...

The AJAX request fails to trigger following the onbeforeunload event except when the page is manually refreshed

I'm currently working on implementing a solution for handling the onbeforeunload event to display a custom message when the user tries to close the browser tab. I want a prompt like: Are you sure you want to leave this page? (I don't want to use ...

Conceal div2 upon clicking button1 and reveal div1 using Angular

When the "Edit" button is clicked, I want to display <div ng-if="hideShow">. Conversely, when the "Add" button is clicked, I want to hide <div ng-if="hideShow1"> and display another <div ng-if="hideShow1">. Currently, clicking on the "Ed ...

Although the web object is not visible, Xpath can still be located

Currently working on automating a Selenium 2.0 code. I am tasked with selecting one or multiple users from a list, then clicking on an "add" button to display their names on a grid. Each user on the grid will have a valid Xpath associated with them when ...

Issue with the smooth scroll to top feature being unresponsive and not functioning

My attempt to create smooth scrolling to the top isn't going as planned. The code provided doesn't seem to be working, and the scrolling remains jumpy... $(function() { $('a[href*=#]').click(function() { if (location.pathname.r ...

How to mimic a mouse hover effect with JavaScript

I'm attempting to replicate a mouse hover effect using JavaScript. Here is the code I have: <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <style> #chart:hover { ...

What is the proper usage of a jwt token?

I'm completely new to this and I've dedicated all my time to figuring out how to create a mechanism for generating JWT tokens. These tokens are necessary for identifying the 'signed in' status of users. I opted for FastAPI, and after s ...

Problem with vueJS List Transition not being triggered

Within my Vue JS App, I encountered a situation where I have a list of items that change order randomly when the user clicks a button. Despite successfully using Vue.set to dynamically reposition the list elements, I faced an issue with adding a transition ...

Could you lend a hand in figuring out the root cause of why this Express server is constantly serving up error

I am encountering a 404 error while running this test. I can't seem to identify the issue on my own and could really use another set of eyes to help me out. The test involves mocking a request to the Microsoft Graph API in order to remove a member fro ...

Verify whether the field includes a minimum number of numerical digits

I am currently using this script to validate whether a field is empty or not. The script works well for me, but I would like to add a condition that the field must contain at least 10 digits (numbers). If it doesn't meet this requirement, I want to di ...

Having trouble displaying images in Express JS

Here are the lines of code that I wrote in Express: res.write("The current temperature is "+temp+". "); res.write("Weather is currently "+weatherDes); res.write("<img src=" +imageURL+ ">"); res.send() ...

Unauthorized Access with Ajax jQuery

While working on an ajax request using Jquery, I encountered a dilemma. Even though the page is only accessible to logged in users, my cookies are not being sent along with the request. This results in a 401 error. I am already logged in, so why aren' ...

Selenium - Locating elements using the power of Ember

I am currently utilizing Selenium in Python 3.6 with the Chrome browser. I have successfully programmed it to navigate to the desired website, but I am encountering difficulty in locating the specific text box element I need. Upon inspection, the element r ...