I am trying to automate the webpage \"http://the-internet.herokuapp.com/exit_intent\" where if we move out of the Viewpane towards the top of the page then the pop up window
You can try the following code: This is using Robot class
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;
import java.awt.*;
public class stackOverFlowQs {
@Test
public void test() throws InterruptedException, AWTException {
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://the-internet.herokuapp.com/exit_intent");
Thread.sleep(3000);
Robot robot = new Robot();
robot.mouseMove(600,0);
Thread.sleep(3000);
driver.findElement(By.xpath(".//*[@id='ouibounce-modal']/div[2]/div[3]/p")).click();
}
}
This is using Actions:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.testng.annotations.Test;
public class stackOverFlowQs {
@Test
public void test() throws InterruptedException {
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://the-internet.herokuapp.com/exit_intent");
WebElement e = driver.findElement(By.cssSelector("h3"));
Actions action = new Actions(driver);
action.moveToElement(e).moveByOffset(600,-1).build().perform();
driver.findElement(By.xpath(".//*[@id='ouibounce-modal']/div[2]/div[3]/p")).click();
}
}