How do I edit a text field in Selenium 2? - junit

I can type text into a field using WebElement.sendKeys() but editing doesn't work: I can neither move the cursor nor delete the last character that I typed with e.sendKeys( Keys.BACK_SPACE )
How do I modify the value of a text field in Selenium 2 (WebDriver)?

You can definitely do that by either of the two methods. I have tried and it works.
e.click() # Positions the cursor at the end of the string
e.sendKeys(Keys.BACK_SPACE )
Or you could simply clear the text, and start over again:
e.clear()
e.sendKeys("What you want to send")

I found this solution that seems to work pretty well. It basically clicks on the text field WebElement, then sends Ctrl-End to put the cursor at the end of the text. Then sends the string that I had previously initialized.
(quickReplyTextArea is a text field WebElement that I have previous found, as is postQuickReplyButton (button instead of text field, obviously). replyText is a String that I initialized earlier)
quickReplyTextArea.click();
quickReplyTextArea.sendKeys(Keys.chord(Keys.CONTROL, Keys.END));
quickReplyTextArea.sendKeys(replyText);
postQuickReplyButton.click();

You can try clicking first into that text box, and use sendKeys() afterwards.

Related

Displaying long value within a disabled text input

I have an input field of type = "text". At the time of entering the details into the input, I can enter a long input. The value is getting stored appropriately in DB as well. After clicking on a submit button, I am disabling the field.
So input is still visible but with only the value (noneditable). The problem arises here as only the length of text box input is being displayed.
Is there any way in which the entire input will be displayed?
One way to do this is instead of disabling the input box, you just remove the onChange event on the inout field and style the text to look like its disabled. if onChange event is something like this:
onChange={() => ()}
It won't be able to change the value of the input field, as it has an anonymous function.
That's one of way of doing it.

Update result of formula in text box

I'm trying to update an unbound text box in a form I'm building.
The text box has a default value which is: =DLookUp("[Metadata]![Username]";"[Metadata]").
When the value in the field username is changed;
how do I update this change in the text box without closing the whole form and then opening it again?
--
I've tried to to do this by adding a button in the form and then on mouse up event try and either by vba or the macro editor find a solution.
It would supposedly be possible to create a macro that will close and then open the form again but it's not really what I'm looking for.
VBA: I found lots of suggestions for requery but I couldn't get this to work:
Set UserName = Forms![Update test]!Text10
UserName.Requery
A general solution that could work with multiple such text boxes is preferable
(but not required, anything that tries to point me in the right direction is welcome).
Go to the design view and select the textbox which represents your table value username, then go to events and select the On Change() event:
Private Sub username_Change()
YourTextbox.Value =DLookUp("[Metadata]![Username]";"[Metadata]")
End Sub

Input Field with text already populated on page load

I have a custom Visual Force page that on load has a name field that is supposed to have {Auto} printed inside the input text box that the user can delete or leave or not. I have been using a html-placeholder however the text just disappears and is gray.
My VF inputfield:
<apex:inputfield required="true"
value="{!EventPackageRevenueBreakdown__c.Name}" html-placeholder="{!Auto}"></apex:inputfield>
What it looks like with that code:
What I need it to look like (notice the cursor is after the closing scope)
Thanks in advance I'm still very new to this!
I suggest you to set Name field in controller with '{Auto}' value.
The placeholder attribute will disappear when there is a value in the field, what you want is to actually set the VALUE of the field to {Auto}.
Try this:
If you want it to automatically clear the field if a user clicks into it, you could add some javascript to handle that.

Receiving click events from separate lines with AS3

I want to receive separate click events from separate lines in a text field, and every time a certain line is clicked by the user, I would like to highlight it and have an event happen.
I would ideally like this to happen with dynamic text, and not have to break the text apart by hand. Using the htmlText property is an option, but I am unsure as to how to bind clickEvents to separate elements.
Where do I begin?
There is no ready to use solution for this. But you can make it yourself using a few things:
set CLICK listener for the whole text field
listen for click and check the caretIndex property
use getLineIndexOfChar to check what's the line of the current caret position
use getLineOffset and getLineLength to get the position of the first and last character of that line
use setSelection to highlight this line
There might be some faster and easier way, but this is what works for sure :)
EDIT: decided to post the solution code, as I was wondering how exactly it works.. and it would be a shame to just leave it unpublished and make you do it instead :)
field.addEventListener(MouseEvent.CLICK, onTfClicked);
function onTfClicked(e:MouseEvent):void {
trace (field.caretIndex);
var line:uint = field.getLineIndexOfChar(field.caretIndex);
var start:uint = field.getLineOffset(line);
var end:uint = start + field.getLineLength(line);
field.setSelection(start, end);
}

Insert text at cursor position in textInput

i need to add text at cursor position on key_up event of keyboard.
first i move cursor using arrow.
then when i was trying to write anything it goes to end of the textInput.
because i used setrange().
Here is my code sample.....
var view:MainView;
eventMap.mapListener(view.numDisplay,KeyboardEvent.KEY_DOWN,onKeyBoardKeyDown);
private function onKeyBoardKeyDown(vEvent:KeyboardEvent):void
{
view.numDisplay.selectRange(view.numDisplay.text.length, view.numDisplay.text.length);
var cno:String=String.fromCharCode(vEvent.charCode);
var no:String=view.numDisplay.text;
if(no=="0") no="";
view.numDisplay.text=no+cno;
}
example:-
if i write
hii alll
then its ok.
after that i use arrow key to move cursor.
let's say my cursor was at
a
then if write any thing then it appears like
hii alll123
But i need output as
hii a123lll
i don't know why you are using the line:
view.numDisplay.selectRange(view.numDisplay.text.length, view.numDisplay.text.length);
but maybe you can change it to
view.numDisplay.selectRange(view.numDisplay.caretIndex, view.numDisplay.caretIndex);
to set the selection to the actual cursor position so your text won't be at the end but at the correct position.
Did you try without the line ? what problem do you try to correct with this ?
With the standard behavior, the cursor is always after the last character typed. I don't understand why you want to force it to be at the end of the text.