无法移出ViewPort窗格-Selenium [英] Unable to Move Out of ViewPort Pane - Selenium

查看:79
本文介绍了无法移出ViewPort窗格-Selenium的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使网页" http://the-internet.herokuapp.com/exit_intent自动化",如果我们朝着页面顶部移出Viewpane,则会弹出窗口,并显示一条消息.但是我无法在硒的帮助下做到这一点,有什么办法可以执行此操作?

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 appear with a message. But I am unable to do it with the help of selenium, is there any way we can perform this action?

推荐答案

您可以尝试以下代码:这是使用机器人类

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

这是使用操作:

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

这篇关于无法移出ViewPort窗格-Selenium的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆