Struggling to locate the element for clicking or sending keys in Selenium using Java?

Hi everyone, I'm a new member of this forum and I'm just starting out with coding for the first time.

I have encountered an issue with a specific part of my code:

md-input-container class="md-default-theme md-input-invalid">>
label for="input_4">Email</label>
input name="emailField" type="email" ng-model="email" ng-change="resetValidity()" auto-focus="" validate-email="" required="" class="ng-pristine md-input ng-valid-email ng-invalid ng-invalid-required ng-touched" id="input_4" tabindex="0" aria-required="true" aria-invalid="true" style="">
!-- ngIf: forgot_password.emailField.$invalid && forgot_password.$submitted -->
/md-input-container>

The ID of the field changes every time I open a session. I've tried the following solution:

WebElement emailField = driver.findElement(By.cssSelector("input[name='emailField']"));
emailField.click();
emailField.sendKeys("aa@aa");

This element can also be found on the URL: "ocloud.optitex.com". If you go to "forgot password," I'm attempting to locate the email field, click on it, and input text.

Unfortunately, nothing happens when I run the code. Instead, I receive the following error message:

No such Element Exception, unable to locate element.

I would greatly appreciate any assistance on how I can successfully click on the field and input text.

Answer №1

Implement the use of an Implicit wait in your code to allow enough time for locating the element before throwing an exception.

driver = new ChromeDriver();    
driver.manage().window().maximize();
driver.get("https://ocloud.optitex.com/#/login/");
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.findElement(By.xpath("//button/span[contains(.,'Forgot Password?')]")).click();
driver.findElement(By.xpath("//input[@name='emailField']")).sendKeys("<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="badbd8d9faddd7dbd3d694d9d5d7">[email protected]</a>");
driver.findElement(By.xpath("//button/span[contains(.,'Reset Password')]")).click();

Answer №2

Implement xpath methodology;

Locate the email field by using the driver.findElement method and supplying the xpath expression for locating an input element with the name attribute equal to 'emailField'.
Perform a click action on the email field web element.
Input the email address "aa@aa" into the email field.

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

Utilizing JavaScript to create multiple HTML tables from JSON data

Is it necessary to create separate tables in HTML for each set of JSON data when all tables have the same number of columns (2 columns)? I am looking to minimize the JavaScript function that displays the table with the current JSON data. Can I use one tabl ...

Tips for getting the jQuery accordion to return smoothly to its original position (instead of stacking on top of each other)

I'm a complete beginner at this and could really use some assistance. Here's my JS Fiddle: http://jsfiddle.net/hAZR7/ The problem I'm facing seems to be more related to logic or math, as the animation works fine when starting and moving to ...

What is causing my Bootstrap Controls to malfunction?

I'm trying to create a Bootstrap carousel that shows 3 items at once and includes controls to switch between them. The carousel I've made does display the three items, but for some reason, the controls are not responding when clicked. I'm un ...

Utilizing Java collections to efficiently generate a sorted view without the need to duplicate the original data

Is there a way to dynamically sort the contents of a collection without making a copy? UPDATE: The collection being sorted is a read-only list. ...

Deciphering the AngularJS Component Hierarchy and Managing Identifiers for Freshly Generated Objects (using HTTP)

In my project using Angular 1, I have developed a todo list application which consists of two components. The first is a smart (container) component responsible for server-side interactions, while the second is a dumb/pure/stateless presentation component ...

Guide on looping through deeply nested children within an object to accumulate a list of names

Within an object, there are numerous parent and child elements var obj={ name: 'one', child:{ name: 'two', child:{ name: 'three', child.. } } } foo(obj) Create a ...

The functionality of .map() in Javascript is non-existent

I am completely new to this community (and JavaScript is also new for me), so I apologize in advance for asking some very basic questions. I have an HTML page with various images, all of which share a common class. After using getElementsByClassName, I obt ...

New feature incorporated at the end of choices in MUI auto-suggest widget

Currently, I'm working on enhancing a category adder feature. Previously, I had limited the display of the "add category chip" to only appear for the no-options render scenario. However, I came across an issue where if there was a category like "softw ...

Find text within a series of brackets

Dealing with a long JSON string can be tricky, especially when trying to filter out specific data between brackets. If you have multiple nested brackets, your regex pattern may not work as expected. Let's take a look at the JSON string: String j ...

Automate Workflow with Selenium

Presently, I have developed a web application that retrieves account details upon entering an account number or bill number. I have over 700 accounts and I require the address for each of them. Since this task is repetitive and manual, I am considering a ...

Javascript Error - Issue with Fuse.js: e.split() function is not recognized

Scenario - I am in need of implementing a fuzzy search feature, and therefore utilizing fuse.js for this purpose. I obtained the code snippet from fuzzy.min.js at https://github.com/krisk/Fuse/blob/master/src/fuse.min.js Challenge - Despite using the cod ...

Ways to discover the present date and transition to the following date?

Currently, I am encountering an issue with my automation script. My script utilizes the selenium tool along with Java language. The specific problem I am facing involves the need to view the current date after clicking on a calendar and verifying if a flig ...

Unleashing the power of XPath and wildcards in AJAX

Can anyone explain why the variable objProperties, which contains an xpath with a wildcard, is coming up empty in this scenario? function getXMLServerObject (httpType, cmd, isAsync) { var object = new Array(); $.ajax({ type: httpType, ...

A comprehensive guide on creating a package that combines an href link with an <li> element

I am currently using the <li> tag to display href links. The issue I am facing is that when I click on the 'box,' it does not directly link to another page. Instead, I have to click on the href link for it to redirect to another page. Is th ...

Utilizing separate JavaScript files in Bootstrap 5: A guide to implementation

I am currently using Bootstrap, but I am looking to decrease the size of the Javascript files being used. My main requirements are dropdown/collapse and occasionally carousel functionalities, so I only want to include those specific scripts. Within the "d ...

Java regex to separate a string by commas

I am looking to split a string from a csv file, which may include commas within double quotes or within JSON. For example: abc, pq"r,s", {"one":1, "two":2} The desired outcome is to split the above string into three tokens: ...

Troubleshooting problem with input fields in Protractor due to sendKeys malfunction

My current task involves automating end-to-end tests using Protractor on an Angular application. However, I've encountered an issue with sending keys to input fields. The sendKeys function consistently misses a few characters each time it is used, so ...

Is it possible to retrieve the HttpsError status from a Firebase function?

Within my firebase function, I deliberately throw an error with a specific status and message using the following code: throw new functions.https.HttpsError('permission-denied', 'Token does not match'); When I receive the server respo ...

Tips for verifying the contents of a textbox with the help of a Bootstrap

I am still learning javascript and I want to make a banner appear if the textbox is empty, but it's not working. How can I use bootstrap banners to create an alert? <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8&g ...

Using Jquery Ajax to Develop Laravel Dropdown Selection with Cascading Feature

I have been working with Laravel 5.6 and encountered an issue with my dropdown selection. Although I selected a province from the dropdown menu, the city menu did not display the corresponding cities. Below is the controller code that I am using: public f ...