Need help automate iPhone keyboard input throught javascript - javascript

I am trying to automate iPHone UI testing throught JavaScript.
I am in a compose mail page and I need to enter email-id in the TO,CC & BCC fields. I have the focus in TO field and keyboard is displayed. To field is UIATextField, however the usual way of entering data into textfield is not entering the data.
I used the following code
var app = UIATarget.localTarget().frontMostApp();
app.keyboard().elements()["go"].tap();
But did no good for me :(
I want to input the email address(abc#xyz.com) through the displayed keyboard.
Please help me with a code snippet. Also please let me know how to change the focus from "TO" field to "CC" which are one below the other.
The Header, Body buttons on the page are a segmentedControls. I am not able to tap them using the code snippet.
var app = UIATarget.localTarget().frontMostApp();
app.segmentedControls()[0].buttons()["Body"].tap();
Please help me with this.
Thanks in Advance
Kiran

I think you could do this a little better and with some reusability. Try defining a method like this:
function typeCharacters(inputString) {
for(var i in inputString) {
target.frontMostApp().keyboard().typeString(inputString[i]);
}
target.frontMostApp().keyboard().typeString("\n");
}
A quick test of this might look like this:
var timestamp = new Date().toString();
typeCharacters(timestamp);
Then you sit back and enjoy watching the keyboard type out a nice date for you.

Finally figured out how to automate the keyboard tapping
This is the code snippet which worked for me
//Get the keyboard handle
var keyBoard=app.keyboard();
//Get the handle for keys
var keys = keyBoard.keys();
//Get the handle for buttons on the keyboard (Space, Enter, Shift etc)
var keyButtons = keyBoard.buttons();
//To type "hi"
//type "h"
keys.firstWithName("h").tap();
//insert a delay for the tap() action to be completed
target.delay(0.5);
keys.firstWithName("i").tap();
target.delay(0.5);

Related

Place cursor back automatically into erroneous form field when js validation fails

Let's say there is a form field named txtphone and then with javascript I check it is at least 10 digits in length. User enters only 5 digits so validation fails. I want the cursor to go back to where the txtphone is input automatically so the user can not get any further without entering a 10 digit phone number. This is an example. I can not get it to go back to input field on fields like name, email, etc. On this example, on failure, this is how I am trying to accomplish this:
txtphone.focus()
txtphone.select()
return False
It shows the alert error message but the focus is placed on the next form field.
Please, respond only if you had this problem in the past and you solved it, and please, give me a few lines of actual working code. I have been fighting this for weeks and ready to give up. Answers like "have you tried..." do me no good. Thank you.
I created a JSFiddle showing how the focus method should work for what you're looking for. Let me know if it helps.
JSFiddle
HTML
<input id="txtphone" type="text">
<button id="btn">
Click me!
</button>
JavaScript
var txtphone = document.getElementById("txtphone");
var button = document.getElementById("btn");
button.addEventListener("click", function () {
if (txtphone.value.length < 10) {
txtphone.style.backgroundColor = "red";
txtphone.focus();
} else {
txtphone.style.backgroundColor = "white";
}
});

How to put cursor to the MathQuill (0.10) field so that one can type to edit right away?

I'm developing a simple plugin for Etherpad to edit formulae using MathQuill. When the toolbar is opened, I'd like the cursor to get into the edit field. The field is mathquillified like this:
var MQ = MathQuill.getInterface(2);
var mathQuillEditor = MQ.MathField(mathQuillField, {
spaceBehavesLikeTab: true,
handlers: {
edit: function() {
latexEditor.value = mathQuillEditor.latex(); // update LaTeX field
jQuery(latexEditor).change(); // fire updating of CodeCogs
}
}
});
To get cursor in the edit field, I've tried:
mathQuillEditor.moveToRightEnd();
which visually puts the cursor there, but the blue margin (that points that the editor is active) does not appear and typing doesn't make any effect; and
mathQuillEditor.el().focus();
which doesn't make any visual difference. I've also tried to combine those, but still no success. Any ideas how to do this?
Ok, this wasn't documented, the answer is simply
mathQuillEditor.focus();
After I've rised an issue, this was explained and docs now contain this method.

Textbox is not taking the value that I assign

I have a page with 10 inputs (TextBox).
I set each input value in the Page_Load with
txtColor.Text = "#FFFFFF"
Each input is a color picker. When the user pick a color, the hexa-name is set in the textbox with a javascript piece of code:
document.getElementById(txtColor).setAttribute("value", newColor);
Buuuuuuut when I try to save the changes I DONT KNOW WHY but the values saved are the old ones.
If at first the value was "FFFFFF" but then the user chose "000000" the program ignores that and save the "FFFFFF" in my db.
I'm working with vb.net
I appreciate any kind of help!
Edit:
Oh god, of course it was the thing that Tim Medora say.
I put the 'Not IsPostBack' and everything works just fine.
Thanks a lot, i wasnt able to see my error.
You say you're using vb script, but your post is tagged javascript. It's not clear what you're working with, but in JavaScript I'd do this:
colorPicker = document.getElementById("color-picker");
colorPicker.addEventListener("change", function () { updateTextBox(); });
textBox = document.getElementById("text-box");
function updateTextBox() {
textBox.value = colorPicker.value;
}
Hope this helps...

Using JQuery MaskInput Plugin with a SSN Field

I am trying to use the JQuery MaskInput plugin on a SSN field but I dont see anyway to make it display "***-**-****" after the user leaves the fields.
Did anyone get this working>
I havent tested this, but it may get you headed in the right direction. The masked input plugin has a completed function that can be called when the user has finished entering their value. You can use it to grab the value and store it in a hidden field to retain it and replace the current text with whatever you desire.
var $txt_SNN = $("#txt_SSN");
$txt_SNN.mask("999-99-9999", {
completed: function() {
$('#hdf_SNN').val($txt_SNN.val());
$txt_SNN.val("999-99-9999");
}
});
$txt_SNN.mask("999-99-9999").blur(function() {
$(this).attr('type', 'password');
});`
This should do it. Although I didn't test it.

Identify URLs in a textarea and show them as output using javascript

i have a text area and a click me. In that text area, if a user enters some URLs then the input should be marked invalid on the button click.
For example, if my input is
"StackOverFlow, the greatest codding buddy you could ever have. The URL: www.stackoverflow.com You can also checkout meta.stackoverflow.com which is also super cool"
At button Click the error should be.
"Form submit failed, because you have entered some URLS. The URLs are
- www.stackoverflow.com
- meta.stackoverflow.com"
I would like a pure javascript solution. No jquery please.
Took one of those regex from the link below:
http://regexlib.com/Search.aspx?k=URL
Then :
var input = document.getElementbyId(id_of_your_form);
var x = input.match(/reg_ex_here/g);
if (x.length>0) { // x[i] will hold the url
var urls=x.concat();
alert(urls);
}
It's not properly tested ... but hope you get the idea..

Categories

Resources