本文整理汇总了C#中OpenQA.Selenium.Chrome.ChromeDriver.GetScreenshot方法的典型用法代码示例。如果您正苦于以下问题:C# ChromeDriver.GetScreenshot方法的具体用法?C# ChromeDriver.GetScreenshot怎么用?C# ChromeDriver.GetScreenshot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenQA.Selenium.Chrome.ChromeDriver
的用法示例。
在下文中一共展示了ChromeDriver.GetScreenshot方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanLoadWebPageTest
public void CanLoadWebPageTest()
{
// add the directory containing chromedriver.exe to PATH
var driver = new ChromeDriver();
var baseURL = "http://localhost:6917/";
try
{
driver.Navigate().GoToUrl(baseURL + "/");
driver.FindElement(By.Id("Name")).Clear();
driver.FindElement(By.Id("Name")).SendKeys("Test");
new SelectElement(driver.FindElement(By.Id("Color"))).SelectByText("Red");
driver.FindElement(By.CssSelector("option[value=\"Red\"]")).Click();
driver.FindElement(By.CssSelector("input.btn")).Click();
var element = driver.FindElement(By.Name("PreviousNames[0].FirstName"), 3);
element.Clear();
driver.FindElement(By.Name("PreviousNames[0].FirstName")).SendKeys("ONe");
driver.FindElement(By.Name("PreviousNames[0].Surname")).Clear();
driver.FindElement(By.Name("PreviousNames[0].Surname")).SendKeys("Two");
var screenshot = driver.GetScreenshot();
screenshot.SaveAsFile("screenshot.png", ImageFormat.Png);
driver.FindElement(By.CssSelector("input.btn.btn-success")).Click();
}
catch (Exception)
{
Screenshot screenshot = driver.GetScreenshot();
screenshot.SaveAsFile("screenshot-error.png", ImageFormat.Png);
throw;
}
driver.Quit();
}
示例2: BrowserTEst
public void BrowserTEst()
{
var drive2r = new ChromeDriver(@"d:\temp\");
// Initialize the Chrome Driver
using (var driver = new ChromeDriver(@"d:\temp\"))
{
// Go to the home page
driver.Navigate().GoToUrl("http://www.hkticketing.com/");
driver.FindElement(By.LinkText("Login/Register")).Click();
driver.FindElement(By.Id("email")).Clear();
driver.FindElement(By.Id("email")).SendKeys("[email protected]");
driver.FindElement(By.Id("login")).Click();
driver.FindElement(By.Id("uniform-login")).Click();
driver.FindElement(By.Id("pw")).Clear();
driver.FindElement(By.Id("pw")).SendKeys("xxxxx");
driver.FindElement(By.Id("login")).Click();
driver.Navigate().GoToUrl("https://www2.hkticketing.com/HKTWebApp/Booking.do?contentCode=MCCHEER0716&language=en_US");
// Get the page elements
var userNameField = driver.FindElementById("usr");
var userPasswordField = driver.FindElementById("pwd");
// Take a screenshot and save it into screen.png
driver.GetScreenshot().SaveAsFile(@"d:\temp\screen.png", ImageFormat.Png);
}
}