Unable to Move Out of ViewPort Pane - Selenium

后端 未结 2 1640
小鲜肉
小鲜肉 2021-01-16 23:47

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

2条回答
  •  有刺的猬
    2021-01-17 00:37

    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();
        }
    }
    

提交回复
热议问题