In this tutorial we are going to see how to handle "Modal Dialog Window" using Selenium Webdriver
Disadvantage using Selenium
- Use Can't handle elements which is inside Modal Dialog Window.
Using Robot Class
- Using Robot Class we can handle Modal Dialog Window.
In this tutorial
- Open http://vodkabears.github.io/remodal/#
- Click on Show button
- In the Modal Dialog Window. Click on Follow button
Source Code :
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.Toolkit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import java.awt.datatransfer.StringSelection;
import java.awt.event.KeyEvent;
public class robot_demo {
public static void main(String[] args) throws InterruptedException, AWTException {
WebDriver driver=new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://vodkabears.github.io/remodal/#");
Thread.sleep(5000);
driver.findElement(By.linkText("Show")).click();
Thread.sleep(7000);
Robot rb=new Robot();
rb.keyPress(KeyEvent.VK_TAB);
Thread.sleep(2000);
rb.keyPress(KeyEvent.VK_TAB);
Thread.sleep(2000);
rb.keyPress(KeyEvent.VK_TAB);
Thread.sleep(2000);
rb.keyPress(KeyEvent.VK_TAB);
Thread.sleep(2000);
rb.keyPress(KeyEvent.VK_TAB);
Thread.sleep(2000);
rb.keyPress(KeyEvent.VK_ENTER);
}
}
Hope you like this post
Thankyou.
we could also use 'keys.chord(keys.tab, keys.enter)'
ReplyDeletewhy to use robot class when we could use keys method ?
Is there any advantage by using this ?
No advantage of robot with new Actions class in WebDriver 2.0
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteI am having bootstrap3 modal dialogue. i am able to handle it from mozilla. But in chrome selenium is not at all detecting the pop up. How to resolve this issue
ReplyDeleteYes its done but u can use normal findelement with xpath and its working....
ReplyDeleteNo word to say about this blog. It was great and useful for us. Thanks Selenium Training in Pune
ReplyDeleteThis comment has been removed by the author.
ReplyDeletevery beautiful very well writtenfreevideoeditor.site
ReplyDelete