我想翻阅笔记本,,不使用任何按钮或类似的东西,但实际上点击页面的活动元素,或通过拖动页面到下一个页面。笔记本电脑和这一个很相似。我尝试了许多不同的方法,但都失败了。
我试着去工作的代码是:
WebElement page= driver.findElement(By.xpath("//*[@id='pages']/section[4]/div"));
Actions kkk = new Actions(driver);
Actions flip= kkk.moveToElement(page, 780, 200);
flip.click().build().perform();我还尝试了下一个方法:
flip.perform();
Thread.sleep(200); //to allow the mouse to hover and activate the page
flip.click().perform();没有什么工作,鼠标悬停在蜜柜的地方,如果我试图点击在同一个地方,它只是重置和页面回滚平。
另外,如果不使用偏移量(坐标),我想不出任何其他方法可以找到花环位置(元素的活动点)。
发布于 2012-11-08 14:06:58
这似乎更多地体现在drag and drop上。
试着做这样的事
WebElement draggable = browser.findElement(By.xpath("//*[@id='pages']/section[4]/div"));
new Actions(browser).dragAndDropBy(draggable, 200, 10).build().perform(); 基于
org.openqa.selenium.interactions.Actions.dragAndDropBy(WebElement source, int xOffset, int yOffset)
更新
或者是这边
WebElement element = driver.findElement(By.name("source"));
WebElement target = driver.findElement(By.name("target"));
(new Actions(driver)).dragAndDrop(element, target).perform();更新2
或者是这边
Actions builder = new Actions(driver);
Action dragAndDrop = builder.clickAndHold(someElement)
.moveToElement(otherElement)
.release(otherElement)
.build();
dragAndDrop.perform();https://stackoverflow.com/questions/13290211
复制相似问题