I am still new to Selenium test world, and I am currently using the selenium chrome webdriver for testing.
what I want to do is in the below popup dialog:
- input a number in text input box
- click the Apply button
- then web application will be triggered to post info to server-side.
my code:
/*
....
a bunch of assert and wait.until function to make sure everything is correct till this step.
....
*/
driver.findElement(By.xpath(DIALOGBOX + "/input")).sendKeys("10");
//Thread.sleep(500);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath(APPLY_BUTTON)));
new Actions(driver).moveToElement(driver.findElement(By.xpath(APPLY_BUTTON))).click().perform();
and here is what I discovered till now, If I uncomment Thread.sleep(500)
, everything will work perfectly. but without Thread.sleep(500)
, the web application will not make a post call to the server which the Apply button should trigger.
I do not know why it happens, what Thread.sleep(500)
made difference to click action, is selenium takes the time to move to the element and performs the click with the mouse not yet reach the button position? and how to fix my cases without using thread sleep?
Update and solution:
first, I forget to mention that the web application is built on GWT(Google web toolkit)
. I have already make sure the driver has successfully got the button element before click(), so the bug is minimized to click() of Action.
then I tried
new Actions(driver).moveToElement(driver.findElement(By.xpath(APPLY_BUTTON)).sendKeys(Keys.ENTER).perform();
it works perfectly, no need to make the thread sleep. so the cause of the bug is that selenium's click action is different from how GWT handle the onclick function. If you face the same issue, try using sendKeys and for the client side adding handler for onKeyPress