我是硒的初学者。
我有很长的可滚动表单,它将自动填充脚本,有没有一种方法可以在每次向下滚动页面时截取屏幕截图(网络驱动程序滚动以填充表单,我没有编写向下滚动的脚本因为网络驱动程序会处理它),以便可以在多个屏幕截图中捕获整个表单。
这是我将如何做到的。每次滑动您都可以截图,就像步骤截图一样。
以下是截图的部分代码:
public static String takeScreenshot(WebDriver driver) {
driver.get("http://www.google.com/");
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
// Now you can do whatever you need to do with it, for example copy somewhere
File dest = new File("c:\\tmp\\screenshot.png");
FileUtils.copyFile(scrFile, dest);
return dest.getAbsolutePath();
}
这是垂直滑动的代码:
public static void swipeVertical(WebDriver driver) {
Dimension size = driver.manage().window().getSize();
System.out.println(size);
int starty = (int) (size.height * 0.70);
int endy = (int) (size.height * 0.30);
int startx = size.width / 2;
new TouchAction(driver)
.press(startx, starty)
.waitAction(Duration.ofMillis(1000))
.moveTo(startx, endy)
.release()
.perform();
}
所以我的伪代码如下所示:
...
重复直到结束...
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句