Unable to Move Out of ViewPort Pane - Selenium

后端 未结 2 1627
小鲜肉
小鲜肉 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:29

    For me this is working , using the webrowser Chrome :

    Actions action=new Actions(driver);
    action.moveByOffset(600, -1).build().perform();
    

    This is not working for me:

    action.moveToElement(e).moveByOffset(600,-1).build().perform();
    
    0 讨论(0)
  • 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();
        }
    }
    
    0 讨论(0)
提交回复
热议问题