How to Read text filled in a Text Box - selenium

Here I am Providing u the Text Box Image with its X-path
and Here is the Code for it, that I had tried:
{
String NameTxtBxData = driver.findelement(By.id("ngoName")).gettext();
System.out.println(NameTxtBxData);
}

The element with id "ngoName" is an input. The text from an input is defined in the value property/attribute:
String NameTxtBxData = driver.findElement(By.id("ngoName")).getAttribute("value");

Hi to read a value form a text filed or any input filed there is a hidden attribute value which keeps the value entered by you inside it hence to read the value in the text box simply do it like below
String NameTxtBxData = driver.findelement(By.id("ngoName")).getAttribute("value");
System.out.println(NameTxtBxData);
Hope this helps you

Related

Get the caret position for Blazor text input

I am working on a Blazor textarea input. What I want to achieve is whenever user types "#" character, I am going to popup a small window and they can select something from it. Whatever they select, I will insert that text into the textarea, right after where they typed the "#".
I got this HTML:
<textarea rows="10" class="form-control" id="CSTemplate" #bind="original" #oninput="(e => InputHandler(e.Value))" #onkeypress="#(e => KeyWasPressed(e))"></textarea>
And the codes are:
protected void InputHandler(object value)
{
original = value.ToString();
}
private void KeyWasPressed(KeyboardEventArgs args)
{
if (args.Key == "#")
{
showVariables = true;
}
}
protected void AddVariable(string v)
{
original += v + " ";
showVariables = false;
}
This worked very well. The showVariables boolean is how I control the pop-up window and AddVariable function is how I add the selected text back to the textarea.
However, there is one small problem. If I've already typed certain text and then I go back to any previous position and typed "#", menu will still pop-up no problem, but when user selects the text and the insert is of course only appended to the end of the text. I am having trouble trying to get the exact caret position of when the "#" was so I only append the text right after the "#", not to the end of the input.
Thanks a lot!
I did fast demo app, check it https://github.com/Lupusa87/BlazorDisplayMenuAtCaret
I got it - I was able to use JSInterop to obtain the cursor position $('#CSTemplate').prop("selectionStart") and save the value in a variable. Then use this value later in the AddVariable function.
you can set your condition in InputHandler and when you are checking for the # to see if it's inputed you can also get the length to see that if it's just an # or it has some characters before or after it obviously when the length is 1 and value is # it means there is just an # and if length is more than one then ...

Sendkeys not sending multiple words

When I pass a single word, e.g. "Gopi", to a text box using sendKeys(), it works. When I try to send multiple words like "Gopi Kingston", the value disappears immediately.
String value = "Gopi Kingston"; // this does not work
Driver.findElement(By.id("searchbox")).sendKeys(value);
String value = "Gopi"; // this works
Driver.findElement(By.id("searchbox")).sendKeys(value);

How to limit the textarea size

I need to limit the textarea to 4 characters...
my current javascript
{
name : "pin",
title : "PIN",
align:"center",
textArea:"isc.TextArea.setCharacterWidth(4)"
}
Can anyone tell me how can I do that please?
You can use following methods both on TextAreaItem and TextItem:
text.setEnforceLength(true);
text.setLength(4);
You can use TextAreaItem field of smartgwt to create multi-line text area.
To restrict the number of characters for this field, setLength can be used.
For example:
private TextAreaItem text = new TextAreaItem("pin", "PIN");
text.setLength(4);
text.setAlign(Alignment.CENTER);

Require a textbox to have value in FIllable PDF

I have a fillable PDF file. I would like to require that a TextBox has a value when the user saves the PDF document i.e. the value is not blank.
Here is what I tried:
(1) Setting the "Required" field on the "TextBox".
PROBLEM: That didn't do much except color the textbox red.
(2) I tried to use the following code in the "onBlur" event:
f = getField(event.target.name)
if (f.value.length == 0)
{
f.setFocus()
//Optional Message - Comment out the next line to remove
app.alert("This field is required. Please enter a value.")
}
PROBLEM: If the user never clicks this box there is no problem
(3) I tried to use the "Validation" tab and run a custom JavaScript.
PROBLEM: If you don't click on the box there is no validation so it is perfectly happy to leave the textbox blank if the user forgets to fill it in
OK, I am out of ideas... Anyone?
Since you are using Acrobat JavaScript I assume you use a viewer that supports and executes Acrobat JavaScript. In this situation you can set the document's WillSave action to a custom JavaScript action and perform validation here. I'm not sure if you can cancel the save operation but at least you can display an alert if the validation fails.
UPDATE: This script will loop through all the fields and display and alert if the field value is empty.
for ( var i = 0; i < this.numFields; i++) {
var fieldName = this.getNthFieldName(i);
var field = this.getField(fieldName);
if (field.value.length == 0)
{
field.setFocus()
app.alert("Field " + fieldName + " is required. Please enter a value.")
}
}
Put the script in document's Will Save action and it will run every time the user saves the form. In Acrobat you set this in Tools > JavaScript > Set Document Actions and select Document Will Save.

Vb.net combobox formatstring property doesn't work

I have a form created in VB.net. It is used to get some information form a user. The form is not bound to any data source.
A combobox on this form is used to enter a cost. I want the value entered by the user to be displayed using currency format. I have used the Format String Dialog that opens from the ellipses button on the FormatString property of the combobox and selected Currency. This put C2 into the FormatString property.
When I run my application, this format is not applied to the value entered into the combobox at the time the number is entered or when I leave the combobox.
What am I missing?
Set the FormattingEnabled Property to True.
The FormatString property works only for data-bound controls. However, the input in a control can still be formatted with the ToString() method on a Change or Leave event.
The code sample below will format the text in the combo box to the default currency once the focus leaves control. Error handling can be done in the else clause:
private void comboBox1_Leave(object sender, EventArgs e)
{
string s = comboBox1.Text;
decimal result;
if (Decimal.TryParse(s, out result))
{
comboBox1.Text = result.ToString("C2");
}
}