Geetanjali C
Geetanjali C

Reputation: 21

Selenium webdriver , testNG with java

How to handle the Modal window?Selenium webdriver , testNG with java

For example: Load https://business.bell.ca/shop/small-business/ Click on Share Via email icon below the Facebook icon on right hand side. Modal window is displayed

How to handle this modal window as i need to take the Screen shot of that modal window?

Upvotes: 0

Views: 141

Answers (1)

Vivek Singh
Vivek Singh

Reputation: 3649

There isnt any modal window. If you are trying to click on Like, its under an iframe. To switch to it perform:

driver.findElement(By.cssSelector(".fui-icon.fui-icon-facebook"))
        .click();
driver.switchTo().frame(
    driver.findElement(By.xpath("//iframe[@title='facebook']")));
driver.findElement(By.xpath("//span[.='Like']")).click();

and to switch to facebook window that follows do:

for (String winHandle : driver.getWindowHandles()) {
    driver.switchTo().window(winHandle);
}

EDIT: Sorry it was my mistake that i took didn't got what you tried to ask. As a workaround if you want to interact with the modal dialog you could use by initially waiting for the modal-dialog to appear, and since its under top-window scope only, you can interact with the fields using xpath or css, whichever you prefer. A sample code for it with xpath would be:

driver.findElement(By.id("shareemail")).click();
new WebDriverWait(driver, 10).until(ExpectedConditions
    .visibilityOfElementLocated(By
        .xpath("//*[@id='emaillightboxmodaljs']")));
driver.findElement(
    By.xpath(".//*[@id='ui-id-3']/div/fieldset/div[1]/div[1]/input"))
        .sendKeys("acd");

Upvotes: 1

Related Questions