Friday, December 30, 2011

Webdriver - Issues with Sendkeys & Click

Webdriver -  Issues with Sendkeys & Click.

During my application automation I have noticed some instances where "SendKeys" and "Click" methods get executed successfully, but no action is performed on the screen.

I feel Webdriver team need to refine these methods further. I am not complaining about them, hats off to the team for merging Selenium1, webdriver and coming up with the architecture that support X Browsers on Y platforms, I like the browser native language concept which created a strong base so that we can make browser handle any user required action.

This issue occurred for the following elements.

1. Text field with numeric validations with default value (0.0).
   onkeypress="return NONUOM_ValidateKey(this, true); onchange="return CalculateLineItemTotal();

2. Elements in a complex Grid.

3. Objects in dynamic frame or some dynamic objects.

How to handle this situation ?

Use Javascipt. Below is the simple example. I have solved most of the issues using this technique.

//driver.findElement(By.id("txtCost")).clear();
//driver.findElement(By.id("txtCost")).sendKeys(UnitPriceInt);
Script = "document.getElementById('txtCost').value='"+UnitPriceInt+"';";
((JavascriptExecutor) driver).executeScript(Script);

---

1 comment: