Error: Element does not exist, cannot find the specified element

I am currently working on automating an email test using JS.

var driver = new webdriver.Builder().withCapabilities(webdriver.Capabilities.chrome()).build();
until = webdriver.until;

driver.get('http://www.automationpractice.com');
driver.manage().window().maximize();

driver.findElement(webdriver.By.linkText("Sign in")).click();
driver.sleep(10000);

var emailInput = driver.findElement(webdriver.By.id("email_create"));
emailInput.sendKeys("<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="fc929d889d929d889d92888f9d8dcd8bbc8c90d28c90">[email protected]</a>");

The error message

UnhandledPromiseRejectionWarning: NoSuchElementError: no such element: Unable to locate element: {"method":"css selector","selector":"*[id="email_create"]"}
is being shown, even though I am certain that the selector exists. Can anyone provide assistance?

Answer №1

It's important to note that the functions you're calling are asynchronous. When you click and put your driver to sleep, the rest of the code continues executing.

To handle this properly, consider using the await keyword within an async function or using .then() to ensure the following code is executed in the correct order.

my_function = async () => {
    var driver = new webdriver.Builder().withCapabilities(webdriver.Capabilities.chrome()).build();
    until = webdriver.until;

    await driver.get('http://www.automationpractice.com');
    await driver.manage().window().maximize();

    await driver.findElement(webdriver.By.linkText("Sign in")).click();
    await driver.sleep(10000);

    await driver.findElement(webdriver.By.id("email_create")).sendKeys("<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6709061306090613060913140616561027170b49170b">[email protected]</a>")
}

Be sure to check if the functions you're invoking return a Promise for proper handling.

Answer №2

The identification does not correspond to the email input field, please attempt this:

let emailField = driver.findElement(webdriver.By.id("//input[@name='email']"));
emailField.sendKeys("<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7917180d1817180d18170d0a1808480e390915570915">[email protected]</a>");

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

Is there a way to extract the content from this webpage using Python and Selenium?

Currently, I am attempting to extract data from a webpage using Python-based Selenium. Unfortunately, I am struggling to grasp the necessary steps to accomplish this task. The specific value that I am aiming to retrieve is located within the red-marked are ...

Issue with Shader UVs in ThreeJS occurs when a glTF model lacks textures

Currently, I am working on importing a glTF model that includes a UV set. My goal is to dynamically assign a texture to it in ThreeJS by injecting shader code into the existing using onBeforeCompile(). So far, everything functions properly. However, when ...

JavaScript: Retrieve the Vertical Position of a Text Within a Division

Simply put, I am looking to implement a basic search feature within my HTML div. Each potential search tag is enclosed by $ and every tag is unique. My objective is to develop a function that takes a tag, scans the div, and identifies the line (Y position ...

Creating CSS for a specific class on a single webpage can be achieved by targeting that class

Here is my custom style: <style> ul { padding:0 0 0 0; margin:0 0 0 0; } ul li { list-style:none; margin-bottom:25px; } ul li img { cursor: poin ...

Angular, NodeJS, and Socket.io present a challenge when it comes to tallying the number of online users

I am facing an issue with accurately displaying the number of online users. When a user connects, the count increases and decreases when they disconnect. However, the problem arises when I refresh the page as the count continues to increase. I am using Ang ...

Using JavaScript, a checkbox can be employed to insert text into a textarea

I have a simple Javascript task that I'm trying to accomplish without using JQuery. My goal is to toggle the text in a textarea based on the state of a checkbox. When the checkbox is unchecked, I want the textarea to display "Hello", and when it' ...

"Embrace the Tempus Dominus integration for the latest version of Bootstrap -

After reading through the script documentation, I attempted to implement it on my example page. However, I keep encountering the error: Uncaught TypeError: $(...).datetimepicker is not a function. Here's the code snippet that I included in the head s ...

When implementing afui and jQuery on PhoneGap, an error was encountered: "TypeError: Cannot read property 'touchLayer' of object function (selector, context)"

While working on deploying a web application using phonegap with afui (Intel Appframework UI) for Android, I encountered an issue when testing it in the android emulator. The debug console displayed the following error right after launching the app: Uncau ...

Guide to connecting a different HTML page to a thumbnail image using jQuery

let newColumnBlock = $('<div class="col-md-2">'); let newImagePoster = $('<img>'); let newSelectButton = $('<a href="secondPage.html"><button class="selectButton"></button></a>'); let movie ...

Reorganizing an array using a custom prioritized list

Is it possible to sort an array but override precedence for certain words by placing them at the end using a place_last_lookup array? input_place_last_lookup = ["not","in"]; input_array = [ "good", "in", "all&qu ...

"Using Vue to compute the sum or calculate values within an array - a step-by

Having a data array like this "item_tabel": [ { "method": { "select_method": 6, }, "innovation": { "select_innovation": 2, }, } ], How do I calculate the sum? This i ...

Integrating React js with Layout.cshtml: Mastering the Fusion of React Routing and ASP.NET MVC Routing

My current project involves an ASP.NET MVC core application with the View written in cshtml. The routing follows the conventional asp.net mvc routing pattern. However, I've recently implemented a new module using React JS. Now, I'm faced with the ...

Align text to the center vertically on the screen

I am struggling to vertically center my text on a page. Whenever I click a button, the page becomes gray with a loading message. Although I've managed to horizontally center it, vertical alignment is posing a challenge. CSS .LockOff { display: n ...

What steps do I need to take to show WebStorm that my userscript is successfully loading jQuery?

My situation involves a userscript that utilizes the @require directive in the metadata block to load jQuery from an external source: // @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js It seems like WebStorm isn't awar ...

javascript - increase counter by milliseconds

I am looking to enhance my JavaScript quiz counter by adding milliseconds. Currently, the quiz only tracks and displays time in seconds (stored in MySQL as a number of seconds, like 120 for 2 minutes displayed as 02:00). I now want to include milliseconds ...

How can animations be disabled in Angular/Javascript?

I have been assigned the task of developing an Angular component for my company's applications that will include a toggle to disable all animations within the app for accessibility purposes. It is important to note that I am unable to go into each in ...

Finding and capturing all the image IDs in a Java Webdriver Selenium script

When browsing, I have a variety of img elements with unique id's that change dynamically with each selection of the release date. Can you provide me with a Selenium WebDriver script that can click on the checkbox image, even if the id of the image ch ...

What is the best way to replace a regular expression in JavaScript?

I've recently been exploring the functionalities of MathJax, a Javascript library that enables the use of LaTex and similar mathematical markup languages within HTML. However, when attempting to incorporate it into my Javascript code, I encountered so ...

What is the procedure to authenticate a specific row within a table using the ROBOT framework?

When adding a new device, I want to ensure that the second row in a table is validated using the ROBOT framework. For example, how can I validate a specific row in a table with the ROBOT framework? https://i.sstatic.net/Ovqp7.png Appreciate your help! ...

"Strategic victory in a board game - employing an advanced search algorithm

Currently seeking an efficient algorithm to detect a "win" situation in a gomoku (five-in-a-row) game played on a 19x19 board. A win occurs when a player successfully aligns five, and ONLY five, "stones" in a row (horizontally, diagonally, or vertically). ...