如何使用SeleniumJava使用Krypton捕获屏幕截图
我想寻求帮助,如果有一种可能的方法/代码来捕获使用JAVA selenium的Krypton平台下的屏幕截图。我在标准化方面遇到了麻烦。谢谢如何使用SeleniumJava使用Krypton捕获屏幕截图,java,selenium,selenium-webdriver,screenshot,krypton,Java,Selenium,Selenium Webdriver,Screenshot,Krypton,我想寻求帮助,如果有一种可能的方法/代码来捕获使用JAVA selenium的Krypton平台下的屏幕截图。我在标准化方面遇到了麻烦。谢谢 var driver = new ChromeDriver() driver.get("https://login.bws.birst.com/login.html/") File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE) FileUtils.copyFile(
var driver = new ChromeDriver()
driver.get("https://login.bws.birst.com/login.html/")
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE)
FileUtils.copyFile(scrFile, new File("c:\\tmp\\screenshot.png"))
根据屏幕截图,导入/类似乎存在一些差异。进一步简化项目范围内的创建目标文件夹,例如下面的屏幕截图目录: 要使用Java捕获屏幕截图,可以使用以下解决方案:
- 代码块:
package screenShot; import java.io.File; import java.io.IOException; import org.apache.commons.io.FileUtils; import org.openqa.selenium.OutputType; import org.openqa.selenium.TakesScreenshot; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; public class takesScreenshot { public static void main(String[] args) throws IOException { System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe"); ChromeOptions options = new ChromeOptions(); options.addArguments("start-maximized"); options.addArguments("disable-infobars"); options.addArguments("--disable-extensions"); WebDriver driver = new ChromeDriver(options); driver.get("https://login.bws.birst.com/login.html/"); new WebDriverWait(driver, 20).until(ExpectedConditions.titleContains("Birst")); File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(scrFile, new File(".\\Screenshots\\Mads_Cruz_screenshot.png")); } }
- 拍摄图像:
您能否用您在标准化方面面临的确切问题更新问题,以帮助我们找出问题所在?我现在没有屏幕截图的任何代码段,但我有使用selenium Java的参考,但在krypton中使用时,它不起作用,这就是为什么我不确定我是否可以向您指出一个现有的讨论,或者您需要一个不同的新答案。你的代码测试和错误在某种程度上会对我们有所帮助。那么你到底被困在哪里了?所有的对象都不工作,我想问一下,当使用氪星作为平台时,实现屏幕截图的正确方法是什么?我已经试着在我的代码上实现了,删除了驱动程序部分,因为我有自己的设置。现在我有问题的“文件scrFile”部分,但我有我的导入库,我不知道为什么它不工作,请参阅最新的照片附件。我已经导入了java.io.File;idk为什么它仍然不起作用