我尝试使用IE11的Actions dragAndDropBy()和机器人类,其中 WebDriver驱动程序=新的InternetExplorerDriver() 但是没有运气。也尝试过机器人课。
dragAndDrop()正在使用DesiredCapabilities
DesiredCapabilities cap = DesiredCapabilities.internetExplorer();
cap.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
cap.setCapability("requireWindowFocus", true);
WebDriver driver= new InternetExplorerDriver(cap);
但是所有click()的鼠标光标也会移动
有什么方法可以拖动元素以偏移?
// ====尝试了操作
WebDriver driver= new InternetExplorerDriver();
driver.get("https://www.w3schools.com/htmL/html5_draganddrop.asp");
WebDriverWait wait = new WebDriverWait(driver, 15);
wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.cssSelector("locator")));
WebElement ele=driver.findElement(By.cssSelector("locator"));
actions( driver, ele);
Point p=ele.getLocation();
Actions act=new Actions(driver);
act.dragAndDropBy(ele, 200, 0).build().perform();
// ====尝试过机器人课
Robot robot = new Robot();
robot.mousePress(InputEvent.BUTTON2_DOWN_MASK);
robot.mouseMove(p.getX()+150, p.getY());
robot.mouseRelease(InputEvent.BUTTON2_DOWN_MASK);
不使用DesiredCapabilities,我们可以将元素拖到offSet