Retrieve the input value using send keys and display it in the console using Selenium WebDriver

I am currently working on a project where I am integrating the Selenium Webdriver with the Chrome implementation in Javascript. The project involves testing a simple quantity input form, and I am struggling with a particular aspect of it. My challenge lies in retrieving the value entered using the sendKeys function and then printing a message based on that value.

If the input value exceeds 100, I want to display "Exceeds 100".

If the input value is less than 0, I want to display "Below 0".

If there is no input value, I want to display "No input".

The test successfully enters new values into the form, but my issue is capturing the value and displaying the corresponding message. Despite trying various approaches, I have found limited documentation on this specific issue. I have provided a link to my code below for reference, and I welcome any suggestions or insights you may have as this problem has me perplexed.

Furthermore, I am curious if assertions can be utilized to address this concern...

Test File Link:

https://gist.github.com/anonymous/89a84dbc15ba4088719400be1f359045

Answer №1

One useful method in Selenium WebDriver is getAttribute(String attrName). This method takes a string parameter which represents the attribute name for which you want to retrieve the value.

WebElement element = driver.findElement("your unique element locator");
String valueText = element.getAttribute("value");

Answer №2

In response to the previous answer, I recommend including a .getText() method to ensure the attribute value is converted to a String.

WebElement element = driver.findElement("your unique element locator");
String valueText = element.getAttribute("value").getText();

It would be helpful to include the complete error message and perhaps a screenshot of the console for further assistance.

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

Creating nested components in Vue.js

I'm currently working on a project that involves generating HTML from JSON data. Here is the JSON snippet I am working with: "type": "span", "content": [ { "type": "span", "content": [ { "type": "div", "content": [] ...

"Angular File Upload Made Easy with Drag-and-Drop Functionality and Cleverly Positioned

Encountering an issue with Angular File upload in conjunction with relatively positioned elements. The drop target is set to 100% width and height, absolutely positioned. While dragging a file over any non-relatively positioned element, the overlay functio ...

Utilizing HTML onClick to pass a PHP variable as a parameter

After going through many similar examples, I am still struggling to get this code working. This is what I currently have: echo('<td colspan="3" style="background-color:#005673; text-align:right; padding: 4px 0px;"> <button class="btnT ...

Possible Inconsistencies with the LookAt Feature in Three.js

Attempting to use the lookAt function to make zombies move towards the character has been a challenge. The problem lies in the fact that they are not turning correctly but at odd angles. Here is the code snippet I tried: var pos = new THREE.Vector3(self ...

Looking to find top-notch keywords that stand out from the rest?

My chosen keyword is s='young girl jumping' function selfreplace(s) { var words = ['man', 'jumping']; var re = new RegExp('\\b(' + words.join('|') + ')\\b', 'g&a ...

Effortlessly submit form data in Codeigniter without the need for page refreshing using jQuery ajax

I've been working on submitting form data in the codeigniter framework using ajax and jQuery to prevent page refreshing, but I keep getting a fail message. Since I'm new to ajax, can someone help me troubleshoot this error? This is my Controlle ...

Dynamically load modules within an AngularJS application

Is there a way to dynamically load module scripts? I have 2 JS files: module1.js (function() { var mod = angular.module('module1', []); .... })(); This is the second one: module2.js (function() { var mod = angular.module('m ...

What is the best way to showcase a non-image file that is stored in MongoDB (using GridFS) on a webpage?

I have a project where users can upload documents (not images) that are stored in MongoDB using GridFS. My question is, is there a way to display these documents on the site for viewing instead of just downloading them? I've tried using the createRead ...

Ways to implement a table column as a slider

My goal is to create a single-page website with a table as the main content. The first column of this table should be toggleable by a button. I specifically want to display the first column of the table only on the slidebar and not both the table and the ...

Issue "RangeError: minimumFractionDigits value is invalid" when using ChartJS in a Next.js application

I'm currently working on developing an application utilizing react-chartjs-2.js. The functionality is smooth in my local environment, but when moved to production, I encounter the following error: Application error: a client-side exception has occurre ...

Receive updates on new emails with the Zimbra mail server

In the Zimbra mail server, there are blacklists and whitelists that determine whether to block or allow new incoming emails. However, the process of blocking an email this way can be inconvenient. I am interested in creating a plugin for the Zimbra mail se ...

The ATU report fails to generate when running Maven using the command 'mvn test'

Recently, I integrated ATU Reports into my MAVEN build Framework. Running the testng.xml file yielded successful results. Important Notes: Due to missing dependencies for ATU reports in pom.xml, I had to manually add JARs to the project's build pat ...

The error encountered is: "TypeError: req.flash does not exist as a function in NodeJs

When it comes to working with Registration on a Site, the Validation process is key. In this case, mongoose models are being used for validation and an attempt is being made to utilize Flash to showcase error messages within the Form. However, there seems ...

Encountered an error "Not Found" when attempting to establish an AJAX connection between Javascript and Rails

I'm having an issue with a simple Rails controller method. When I call it from JavaScript as an AJAX method, I get the error message "Not Found" in the JavaScript error log, even though the method works fine when accessed directly in the browser. What ...

Issue with importing Node module (@pusher/push-notifications-web) occurring when page is refreshed in Next.js

Encountering a problem while trying to integrate the node module @pusher/push-notifications-web. More information can be found at https://github.com/pusher/push-notifications-web I'm unsure whether this issue is related to Next.js or the node module ...

Utilizing Selenium IDE for generating a Facebook group editor (redactor) or a text input field within a div

I am facing an issue with adding text to a specific section in my HTML code, which is meant to be the description for a Facebook event. I have tried various methods like using a div or span element, but I believe this might require a redactor tool (althoug ...

Executing an ajax request following validation

I am facing an issue with my ajax insert script and validation script. Currently, the insert script is executing regardless of the validation result. How can I modify my code to ensure that the insert query only runs after successful validation? Below is ...

What is preventing me from opening this local html page without an IIS Server?

Currently immersed in a passion project that can be found at https://github.com/loganhenson/jsrpg This project has been a collaborative effort with a friend, utilizing Visual Studio Professional for development and testing it on my local IIS server. Init ...

Utilize Angular to organize data in a single-dimensional array

In my project, I am using Angular and Bootstrap to create a dynamic data grid where users can edit the data. The dataset consists of an array of objects, with each object containing a non-unique group property to categorize records. For example: [ { ...