我的目标是在硒终端上运行带截图的selenium脚本,正常代码可以轻松地在Ubuntu终端上运行,但是如果我运行带截图的代码,则无法正常运行
代码:
System.setProperty("webdriver.chrome.driver", "/home/dev2/Downloads/newchromedriver/chromedriver");
WebDriver m = new ChromeDriver();
m.get("");
m.manage().window().maximize();
m.findElement(By.xpath(".//input[@id='user']")).sendKeys("");
m.findElement(By.xpath(".//input[@id='pass']")).sendKeys("");
m.findElement(By.xpath(".//button[@id='login_submit']")).click();
m.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
// m.manage().timeouts().implicitlyWait(2,TimeUnit.MINUTES);
m.switchTo().frame("mailFrame");
Thread.sleep(9000);
String row=m.findElement(By.xpath(".//tr[contains(@id, 'rcmrow')]")).getText();
System.out.println(row +"\t");
if(row.contains("ADC: Reminder 3. GENERAL ENQUIRY REQUEST - Qa Hemant Three") && row.contains("Tue")) {
System.out.println("mail recieved");
}
else {
System.out.println("mail not received");
}
String timestamp = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss").format(new Date());
String imgname = "mapscreenshot " + timestamp + ".png";
String fileWithPath = "//home/dev2/Desktop/" + imgname;
Screenshot fpScreenshot = new AShot().shootingStrategy(ShootingStrategies.viewportPasting(1000)).takeScreenshot(m);
ImageIO.write(fpScreenshot.getImage(),"PNG",new File(fileWithPath));
System.out.println("your screenshot is saved at location: " + fileWithPath);
**Terminal output:**
/eclipse-workspace/seffcon$ java -cp /home/dev2/eclipse-workspace/seffcon/bin:/home/dev2/eclipse-workspace/seffcon/libs/* org.testng.TestNG testng.xml
[TestNG] Running:
/home/dev2/eclipse-workspace/seffcon/testng.xml
===============================================
Suite
Total tests run: 1, Failures: 1, Skips: 0
===============================================
我希望Chrome浏览器可以打开,脚本应该可以截屏 但这没有发生