我正在尝试使网页自动化”http://the-internet.herokuapp.com/exit_intent http://the-internet.herokuapp.com/exit_intent“如果我们从视图窗格移向页面顶部,则会出现弹出窗口并显示一条消息。但是我无法在硒的帮助下做到这一点,有什么方法可以执行此操作吗?
您可以尝试以下代码: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();
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)