How to handle modal dialog box in Selenium?

13,785

just write the following code after click on login button:

Thread.sleep(3000); //i use here wait implicit wait. Try to use explicit wait here.

driver.findElement(By.cssSelector("a.Icon.Icon--close.Icon--medium.dismiss")).click();
Share:
13,785
Bharat Mane
Author by

Bharat Mane

Currently working as a Manager SDET in Mastercard @Pune, INDIA location. 9+ years of Experience in manual & Automation Testing for web & mobile applications with 5+ yrs of leading a team of manual and automated testing efforts. My responsibilities evolved from test planning and manual testing on various projects to writing automation and overseeing manual testing efforts from clients, Developing automation tools and processes for the windows Live organization including a web UI automation framework and a test result reporting platform as well as other smaller tools. Working experience in different Software Domains- Banking, CRM-Salesforce, Healthcare, ERP, E-commerce and Web base applications etc. Having working experience on number of tools in Automation (Selenium). Selenium IDE Selenium WebDriver Selenium Grid Maven BitBucket, Git, Jenkins BDD framework with Cucumber & JBehave Mobile Testing (Android & iOS)- Appium AutoIT TestNG, JUnit Sikuli Applitools Log4j Extent Reports in Selenium, Dashboard Report API Testing - Soap, Rest, Postman JMeter I'm always trying to update with latest technologies & I'm still learning many more tools.

Updated on June 04, 2022

Comments

  • Bharat Mane
    Bharat Mane about 2 years

    There is a scenario where I get the modal dialog box when I tried to login.

    I am not able to handle login scenario because webdriver is not getting access to the modal dialog box. Is there any way to handle this?

    See the details in below image: enter image description here

    public class TwitterLogin 
    {
    
        static WebDriver driver;
        static String baseUrl="myURL";
    
        public static void main(String[] args)
        {
            driver= new FirefoxDriver();
            driver.get(baseUrl);
            driver.manage().window().maximize();
    
            //******Click on Login Link**********//
            WebElement LoginButton= driver.findElement(By.xpath("//button[@class='Button StreamsLogin js-login']"));
            LoginButton.click();
    
            WebElement UsernameTextbox=    driver.findElement(By.xpath("//input[contains(@name,'email]')]"));
            UsernameTextbox.clear();
            UsernameTextbox.sendKeys("uName");
    
            WebElement PasswdTextbox=driver.findElement(By.xpath("//input[contains(@type,'password')]"));
            PasswdTextbox.clear();
            PasswdTextbox.sendKeys("1234");
    
         }
    
    }
    

    After clicking on Login button, I'm not able to enter username & password.

  • Bharat Mane
    Bharat Mane over 8 years
    Thanks Noor. I have tried by adding big timeout & it's working now. See below is my code-
  • Bharat Mane
    Bharat Mane over 8 years
    hey, dont mind boss you are correct & I accepted that. Above code, what I hv tried it's also working.
  • Bharat Mane
    Bharat Mane over 7 years
    Why the question has getting downvotes again and again. I want to ask the reason is anything missed? Please explain..
  • noor
    noor over 7 years
    @BharatMane Actually, when any user search and get your question, he can downvote it wisely or unconsciously. Actually i don't know who down vote this question.
  • Bharat Mane
    Bharat Mane over 7 years
    Thanks for the explanation.