Wednesday, June 06, 2012

Deal with Modal Dialog in my WebDriver test

If  you do not have an idea how to deal with the Modal Dialog in WebDriver Tests, here is my solution to it
For example the modal dialog pop-up after clicking "Logout" link, so the code like this:
 driver.findElement(By.linkText("Logout")).click();  
 driver.switchTo().activeElement().sendKeys(Keys.ENTER);  
 driver.switchTo().alert().accept();  

"Mouse" hover to your WebElement as a bonus in case you are looking for:
 //simulate the mouse hover  
 Actions builder = new Actions(ldriver);  
 Action action = builder.moveToElement(sportslink).build();  
 action.perform();  
Hope it helps!

No comments:

Post a Comment