3

A question from a newbie; for exercising, I play with a Bestbuy cart, but a popup on the home page

enter image description here drives me crazy. Just can't figure what kind of popup is that. Without success tried alert handling and it looks like it is not iframe either. Is there any method to handle a "modal dialog".

6

I assume you want to close it. You need to wait for the "close" button to be visible and then click it. Here is what works for me as is:

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;


public class Test {
    public static void main(String[] args) throws InterruptedException {
        WebDriver driver = new FirefoxDriver();
        WebDriverWait wait = new WebDriverWait(driver, 10);

        driver.get("http://www.bestbuy.com/");
        driver.manage().window().maximize();

        // wait for the close button to appear
        WebElement closeButton = wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector(".email-submission-modal .modal-header button.close")));

        closeButton.click();

        // do smth
    }
}
  • Thank you for your answer Alecxe. Yes, I want to close. I wonder if you know how it can be done with Selenium/JAVA? – Paul M Jun 28 '17 at 2:25
  • @PaulM updated with a java sample. – alecxe Jun 28 '17 at 2:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.