gpt4 book ai didi

c# - Selenium 屏幕截图参数无效

转载 作者:行者123 更新时间:2023-11-30 23:15:09 26 4
gpt4 key购买 nike

这是我的 Selenium 测试:

    [Test]
public void RunStepsTest()
{
using (var driver = new InternetExplorerDriver())
{
driver.Navigate().GoToUrl(Url);
ExecuteStep(driver, "start");
ExecuteStep(driver, "step1");
ExecuteStep(driver, "step2");
ExecuteStep(driver, "finish");
}
}

private void ExecuteStep(InternetExplorerDriver driver, string stepName)
{
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
wait.Until(x => ExpectedConditions.ElementIsVisible(By.Id(stepName)));

var scrrenshot = driver.GetScreenshot();
scrrenshot.SaveAsFile(Path.Combine(ScreenshotDirectory, stepName + ".jpg"), ScreenshotImageFormat.Jpeg);

var link = driver.FindElement(By.Id(stepName));
link.SendKeys(Keys.Enter);
}

大部分时间这个测试在线失败

        scrrenshot.SaveAsFile(Path.Combine(ScreenshotDirectory, stepName + ".jpg"), ScreenshotImageFormat.Jpeg);

消息“参数无效”。我做错了什么?

最佳答案

在 Internet Explorer 驱动程序中,它旨在抛出此错误。

来自 Github bug tracking :

Because of the limitations of how the IE driver is forced to work in order to take full-DOM screenshots, screenshots are only supported for browser windows viewing HTML documents. This is entirely as intended by the driver (regardless of the behavior of Chrome or Firefox). The driver is forced by the constraints of the IE browser itself. Accordingly, I'm closing this as "working as intended".

如果您允许使用其他驱动程序,您可以尝试使用 Firefox 或 Chrome 驱动程序进行截图。

关于c# - Selenium 屏幕截图参数无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42751996/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com