Add random value on specific field selenium webdriver - javascript

I'm pretty new to Selenium and Java just wanted to know if there's way I can randomly add a value in a specific field, lets say in "Case ID" field I want to generate a random 8 alphanumeric value, below is the xpath of the field I'm referring to:
driver.findElements(By.xpath(".//*[#id='case_id']")).size() != 0) {
Thanks in Advance,
P

Generate a random alphanumeric string
import java.util.UUID
UUID.randomUUID().toString();
randomUUID() method is used to retrieve a type 4 (pseudo randomly generated) UUID. ex syntax :046b6c7f-0b8a-43b9-b35d-6489e6daee91
In your case you want eight digit alphanumeric String so just split the string
String arr[]=UUID.randomUUID().toString().split("-");
System.out.print(arr[0]);//046b6c7f
Assuming that case id is an input text box just use sendkeys to enter the text into the text box
driver.findElements(By.xpath(".//*[#id='case_id']")).sendKeys(arr[0]);
Hope this helps you.Kindly get back if i misunderstood ur question or if you need any further help

Related

Keeping leading zeros in Adobe Acrobat XI Pro

How do I retain a 0 in the numeric formatted fields when the zero is at the beginning of a number? right now the field drops the 0 and proceeds to display the second number.
For example, in the number field, if i enter "00100", then it displays as "100".
I have written a keystroke script to accept only numbers but I need to limit the numbers to 6 digits
Please help.
function numOnly_ks() {
// Get all of the characters that have been entered in to the field
var value = AFMergeChange(event);
// Do nothing if field is blank
if(!value) return;
// Reject the entry if the entry doesn't match the regular expression
if(!AFExactMatch(/^[0-9 /+]+$/, value)) event.rc = false;
}
One possibility is to add this to the Validate event:
event.value = util.printf("%,106d", event.value) ;
Note: I have not tested it, but it should work. You might have a look at the util.printf() method description in the Acrobat JavaScript documentation.
Do you actually need the field entry to be a numerical value (i.e., do you need to use the value for mathematical purposes)? If not, you can just set the field to be a text entry, which will allow a user to enter numbers as text in the field, and will thus allow the entry of leading zeros. To do this, go to the following menu: Edit>Edit Text & Images>Forms>Edit>[then click on the field you want to edit]>Edit Fields>Show Field Properties>Format>[then set "Select Field Properties" to "None"]. This change will allow a user to enter any characters in the field, so it's not going to be an option for any form owner/creator who needs to limit the field entry parameters/rules for users. But it works as a quick one-off solution to force leading zeros.

Text Input Character Limits

I'm pulling a string back from the database via jQuery, into a textarea, then upon user approval, grabbing that value and placing it in a text input.
Right now, my code looks roughly like this (some omitted of course):
var string = $('#textarea').val(); // Contains 145,095 char string
console.log(string.length); // logs 145,095 characters
// Clear Input and add approved string
$('#input').val('').val(string); // Contains 14,023 char string
Wondering where those ~131,000 characters are going? Based on some initial research, my understanding is that Chrome (in this case) should support millions of characters in a text input, so is this a jQuery limitation? I haven't found anything to support that hunch. Suggested work arounds?
You don't need to clear the input and then add the new value in, the JS can be streamlined to this:
$('#input').val(string); // Contains 14,023 char string
To be sure the value is being truncated, can you try and do a truthy match like so:
if (string === $('#input').val()) {
console.log('the values match');
}
If it does return true then it is just a visual thing, the content of the input box is intact :-) If not, then I would suggest adding a maxlength attribute to the input.
Hope this helps!
probably it is jQuery limitation
try to put Your text by parts or
try to use clear js : document.getElementById('input').value = string;

validation for the "version" field in a table

I have an input field named "VERSION" in a form where I have to write the version of the document.
e.g.
Version : 10.1.2.3
How to validation for this input field in javascript?
Can you use a regular expression?
(\d+\.)+.\d+
Meaning: one or more digits, followed by a point, repeated as many times as you want, followed by a point and one or more digits.
If you have to have 4, you can make it more specific:
(\d+\.){3}.\d+
If it has to be 2 digits, one one one, try:
\d\d\.\d\.\d\.\d
As you see, you need to be more clear about "what is a valid version, and what is not" in order to obtain a more specific answer :]
You mean you'd validate if there is a version input in the correct format?
(use an ID for the input field)
if(document.getElementByID('VERSION').value.match(/^\d+\.\d+\.\d+\.\d+$/)) {}
This should match all versions in the format {number}.{number}.{number}.{number}
Maybe you have to trim the string before you do that

Best way to mask textbox control to allow string value in a pair of 3 character using javascript

I need to mask a textbox control to allow string value in a pair of 3 character using java script.
Eg:- I have a Text box control zip code in which when a user gives input then it should automatically pair them in a pair of 3 character (ABC#123), and total length of input is 6 Max.
Is it possible then how??
var text="ABC123";
//you can add any validation if you require like to check the length of string
//if(text.length<=6)
var output=text.substring(0,3)+" "+text.substring(3);
check this

Checking input values for special symbols

I am having two text fields in my form. The data to be entered in the field are Name and City respectively. I want to check that the user has not entered any special symbols like !,#,#........ i.e, the only thing user should enter must be belonging to a-z,A-Z, though the user can enter Underscore(_), but no numbers, no special symbols.
I want to check this using JavaScript, how can this be achieved.
Thanks in advance.
A classic problem that's usually solved with the help of regular expressions.
var myString = "London";
if (myString.match(/^[a-zA-Z_]+$/)) {
// Success
}
If you want to allow spaces, like for New York, change the pattern to /^[a-zA-Z_\s]+$/.

Categories