當前位置: 首頁>>代碼示例>>C#>>正文


C# ChromeDriver.GetScreenshot方法代碼示例

本文整理匯總了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();
        }
開發者ID:linal,項目名稱:ValidationPOC,代碼行數:31,代碼來源:BasicTests.cs

示例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);
            }
 
        }
開發者ID:heimanhon,項目名稱:researchwork,代碼行數:30,代碼來源:BondSpreadServiceTest.cs


注:本文中的OpenQA.Selenium.Chrome.ChromeDriver.GetScreenshot方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。