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

Should the page.js in a Next.js App router be a server component?

Is it standard practice in Next.js 13 and above (App router) for the page.js of all routes/folders to be a server component? I know that it can be a client component with use client, but is this advisable or are there potential issues during the build proc ...

Is there a way to inform TypeScript that the process is defined rather than undefined?

When I execute the code line below: internalWhiteList = process.env.INTERNAL_IP_WHITELIST.split( ',' ) An error pops up indicating, Object is possibly undefined. The env variables are injected into process.env through the utilization of the mod ...

the modal body is taking longer than expected to load with ajax

I have a unique modal that I'm filling with dynamic data through an Ajax GET request upon modal load. Interestingly, the data is not fetched or added to the modal body unless I trigger an alert first. The structure of my modal is as follows: <div ...

Literal Route Waypoints Guidance Service

I am currently working on an angularjs directive that utilizes the Google Maps Direction Service. In my controller, I have a getFunction that watches for changes in a scope variable. Once the scope variable changes, it triggers the calculateAndDisplayRoute ...

Is Eval really as bad as they say... What alternative should I consider using instead?

After making an ajax request, a JSON array filled with user inputs is returned to me. The inputs have already been sanitized, and by utilizing the eval() function, I can easily generate my JavaScript object and update the page... However, there lies a dil ...

Generating a list of objects from an array of strings

I am currently facing an issue in my code and I could use some help with it. Below are the details: I have a array of string values containing MAC addresses and constant min & max values. My goal is to map over these MAC values and create an array of obje ...

Generating a JSON array from a C# collection can be achieved by utilizing the System.Web.Script.Serialization

Can someone help me with this code snippet? var httpWebRequestAuthentication = (HttpWebRequest)WebRequest.Create("http://api"); httpWebRequestAuthentication.ContentType = "application/json"; httpWebRequestAuthentication.Accept ...

WebSocket connection issues are being experienced by certain users

While using socket.io, I encountered an issue where some users were unable to send messages with the message "I can't send a message why?". After researching the problem, it seems that the firewall or antivirus software may be blocking websockets. If ...

What is the best way to determine the total of values from user-input fields that are created dynamically

Scenario- A scenario where a parent component is able to create and delete input fields (child components) within an app by clicking buttons. The value of each input field is captured using v-model. Issue- The problem arises when a new input field is crea ...

Understanding TypeScript typing when passing arguments to the Object.defineProperty function

After reviewing all the suggested answers, including: in Typescript, can Object.prototype function return Sub type instance? I still couldn't find a solution, so I'm reaching out with a new question. My goal is to replicate Infix notation in J ...

Eliminate negative values in CSS using jQuery

In my AngularJS project, I am utilizing jqLite for some custom CSS properties implementation. Here is an example of how I am incorporating the custom CSS properties: $scope.$on('scrollEvent', function(){ if (a < 5){ a = a + 1/2 ...

What sets AngularJS service, provider, and factory apart?

I'm feeling a bit confused about the service, provider, and factory in AngularJS modules. Can you please explain the differences between these three components and provide examples for better understanding? ...

What is the importance of having the same data type for the searchElement in the argument for Array.prototype.includes()?

Is there an issue with my settings or is this a feature of TypeScript? Consider the code snippet below: type AllowedChars = 'x' | 'y' | 'z'; const exampleArr: AllowedChars[] = ['x', 'y', 'z']; f ...

Retrieve the value of an attribute within a controller function that is not a directive

Here is some HTML content, <button data-href="helloworld">Show href Value</button> And here is some Javascript content, $("body").on('click', 'button', function(){ console.log($(this).attr("data-href")); }); When exe ...

Retrieving content of an element in Selenium Java with css/xpath

I have this HTML structure: <div dir="auto" aria-label="Item-Count-0" class="css-901oao">(0)</div> I am attempting to retrieve the value "0" using XPath/CSS. I am aware that the CSS selector to extract "Item- ...

Despite receiving a return false from the Ajax verification, the form is still submitted when using onsubmit

I have implemented form verification using ajax to check for duplicate usernames. If a duplicate username is found, the function returns false; otherwise, it returns true. Below is the ajax code: function checkform(){ var username = $("#username").va ...

Pseudo-element fails to display in React when applied to a paragraph tag, even with display block property set

I am experiencing an issue where the pseudo element ::after is not appearing in my browser. I am currently working with React.js and Material UI's makeStyles. Here is the code snippet causing the problem: modalTitle: { borderBottom: '2px sol ...

Using AngularJS to display multiple objects in the same ng-repeat loop

Is it possible to display two objects simultaneously in ng-repeat? <tr data-ng-repeat="target in targets |session in sessions |filter:query | orderBy:orderProp"> ...

The specified property is not recognized by the type in TypeScript

I have set up a basic form with validation in Ionic 2. The form functioned properly when I used 'ionic serve' but encountered issues when running 'ionic run'. My suspicion is that the problem lies within my TypeScript code, specifically ...

What is the best way to send additional data with getServerSideProps() in Next.js?

Not sure if this is a silly question, but I am currently working with a Django API and attempting to implement pagination on the search page using Next.js. As a newbie to Next.js, I have scoured the web for a solution but haven't found anything helpfu ...