user391786
user391786

Reputation: 13

Passing Keyboard event not working iOS simulator/device from WebDriver

Scenario: - We have registration form that checks for errors via AJAX - Fields are: email, confEmail, fname, lname, pwd, confPwd - Error check happens when user enters in "email" field and tabs to "confEmail" field. Same for "pwd" and "confPwd" field - I am trying to write automation script that mimics user behavior where user will enter "test" in "email" field and then tab to next field which is "confEmail". This should invoke AJAX check and throw error about "invalid email address"

Test configuration: - Test written in Linux - Running in iPhone simulator on Mac (of course)

This piece of code enters email address: driver.findElement(By.cssSelector(Locators.getLocator("mobilebuy->emailAddressField"))).sendKeys("test");

Since sendKeys will not move focus away from that field, I then send TAB/click to next field so that the AJAX fires up. Apparently, doing that doesn't work. The AJAX never fires and no error message shows up. I can see when I simulate this manually in iPhone simulator, it works.

This should tab to next field: driver.findElement(By.cssSelector(Locators.getLocator("mobilebuy->emailAddressField"))).sendKeys(Keys.TAB);

OR

This should click on next field which should fire AJAX: driver.findElement(By.cssSelector(Locators.getLocator("mobilebuy->confEmailAddressField"))).click();

ANY IDEA ON HOW TO PROCEED WITH THIS ISSUE? I LOOKED THROUGH IT CLOSELY AND EVEN TRIED TO PASS IN UNICODE FOR "TAB" KEY BUT THAT DIDN'T WORK EITHER.

Upvotes: 0

Views: 1939

Answers (2)

user391786
user391786

Reputation: 13

First of all, only the FirefoxDriver supports Action class (according to http://code.google.com/p/selenium/wiki/TipsAndTricks), but you should also expect support for the InternetExplorerDriver too.

Got this to work using following steps: - I have a Type method which types items into the form - Thereafter, I send a click to the field that fires Ajax using Action class and that seemed to work

// (WebDriver, email, confEmail, fname, lname, pwd, confPwd)
TypeRegistrationData(driver, "test/tester@com", "", "", "", "", "");

// action builder that tabs to next field
WebElement we = driver.findElement(By.cssSelector(Locators.getLocator("buy->emailAddressField")));
Actions builder = new Actions(driver);

builder.click(we); // this fires up the ajax that is expected

Upvotes: 1

JacekM
JacekM

Reputation: 4099

Try using Actions chain

Actions builder = new Actions(driver);
builder.keyDown(Keys.TAB).keyUp(Keys.TAB);
builder.build().perform();

If I were really desperate I would try to use sendKeys not necessarily on the text fields but on some parent element (could be even on body itself).

Upvotes: 0

Related Questions