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);
Related
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 ...
I am trying to get XPaths for underlined values in the image below. I have a list of cards which is always different, and I need to grab values from the inside of the highlighted card which has 'highlight' in its class.
When I grab the XPath through inspecting an element in Chrome, I get something like this //*[#id="rental-asset"]/div/div[1]/div/rdo-nav-card-asset[11]/div/div[1]/div/i which doesn't work for me since that 11 in brackets is always going to be a different value. How can I create an XPath for these elements based on their unique class?
Here is how to get the first underlined thing. I think you should be able to take it from here.
//rdo-nav-card-asset/div[contains(#class,'panel') and contains(#class,'highlight')]/div[contains(#class,'panel-heading')]/div[contains(#class,'panel-title')]
You can Split the xpath and iterate in the range they are expected to occur.
Suppose they have that value from 1-22 you can something like this.
This is a python code.
str1 = '//*[#id="rental-asset"]/div/div[1]/div/rdo-nav-card-asset['
str2 = ']/div/div[1]/div/i'
for i in range(1, 22):
str3 = str1 + str(i) + str2
a = driver.find_element_by_xpath(str3).text
print a
You can grab the other elements or data inside the loop.
Comment below if you have any confusion.
You can firstly find the highlight card and use it as the search context of those underline texts.
Code as following:
var activeCard = driver.findElement(By.css('rdo-nav-card-asset > div.rdo-card-highlight'));
// the text of 1rd underline
var title = activeCard.findElement(By.css('.panel-title')).getText();
// the text of 2rd underline
var title = activeCard.findElement(By.xpath('.//div[#class='rdo-card-metric'][1]'))
.getText();
// the text of 3rd underline
var title = activeCard.findElement(By.css('.text-danger')).getText();
// the text of 4rd underline
var title = activeCard.findElement(By.xpath('.//div[#class='rdo-card-metric'][3]'))
.getText();
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
Using below code, it sends key in browser URL not in google search text box.
i want to enter text in google search text field using keyboard event in caps.
driver.get(https://www.google.co.in/);
Actions builder = new Actions(driver);
Action enterText = builder.click(driver.findElement(By.
cssSelector("input[type=text]"))).
keyDown(Keys.SHIFT).
sendKeys("my gmail").
keyUp(Keys.SHIFT).
build();
enterText.perform();
You can use
driver.findelement("YOURELEMENTLOCATOR").sendKeys(Keys.SHIFT,"yourtexttobetyped")
Example,
driver.findElement(By.cssSelector("input[type=text]")).sendKeys(Keys.SHIFT,"stackoverflow")
will send you 'STACKOVERFLOW'. or else you can send the CAPITAL letters directly in the send keys as
driver.findElement(By.cssSelector("input[type=text]")).sendKeys("STACKOVERFLOW")
:)
Below code is to uppercase the first letter of password. It worked perfect for me. Kindly suggest to others too.
String password = "Done123!";
password = password.substring(0, 1).toUpperCase() + password.substring(1);
driver.findElement(By.cssSelector("input[type=text]")).sendKeys(password);
Thanks.
Simple helper function
def capitalized(driver, string):
for char in string:
if char.isUpper():
driver.send_keys(Keys.SHIFT, char)
else:
driver.send_keys(char)
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.