static void Main(string[] args) { PhantomJSDriver driver = new PhantomJSDriver(); driver.Manage().Window.Maximize(); driver.Navigate().GoToUrl("http://sampleapp.tricentis.com/101/"); driver.GetScreenshot().SaveAsFile("screenshot1.png", ScreenshotImageFormat.Png); IWebElement btnTruck = driver.FindElementById("nav_truck"); btnTruck.Click(); driver.GetScreenshot().SaveAsFile("screenshot2.png", ScreenshotImageFormat.Png); driver.Quit(); }
static void Main(string[] args) { var url = "https://passport.cnblogs.com/user/signin"; var driver1 = new PhantomJSDriver(GetPhantomJSDriverService()); driver1.Navigate().GoToUrl(url); if (driver1.Title == "用户登录 - 博客园") { driver1.FindElement(By.Id("input1")).SendKeys("xielongbao"); driver1.FindElement(By.Id("input2")).SendKeys("1234"); driver1.FindElement(By.Id("signin")).Click(); } driver1.GetScreenshot().SaveAsFile(@"C:\aa.png", ScreenshotImageFormat.Png); var o = driver1.ExecuteScript("$('#signin').val('dsa')"); Console.WriteLine(driver1.PageSource); driver1.Navigate().GoToUrl(url); Console.WriteLine(driver1.PageSource); IWebDriver driver2 = new PhantomJSDriver(GetPhantomJSDriverService()); driver2.Navigate().GoToUrl("https://home.cnblogs.com/"); Console.WriteLine(driver2.PageSource); Console.WriteLine(driver1.PageSource); Console.Read(); }
static void TestPhantom() { var driverService = PhantomJSDriverService.CreateDefaultService(); driverService.HideCommandPromptWindow = true; var driver = new PhantomJSDriver(driverService); driver.Url = "https://www.kak-noviy.ru/sell/phones/apple/iphone-5/64gb-white"; driver.Manage().Window.Size = new System.Drawing.Size(1920, 1080); driver.Navigate(); var source = driver.PageSource; var label1 = driver.FindElementByXPath("//label[text()='Как новый']"); var label2 = driver.FindElementByXPath("//label[text()='Устройство полностью исправно']"); var label3 = driver.FindElementByXPath("//label[text()='Полная комплектация']"); var label4 = driver.FindElementByXPath("//label[text()='Блокировки отсутствуют']"); label1.Click(); label2.Click(); label3.Click(); label4.Click(); WaitForAjax(driver); driver.GetScreenshot().SaveAsFile("test.png", System.Drawing.Imaging.ImageFormat.Png); var price = driver.FindElementByClassName("price"); Console.WriteLine(price.Text); driver.Close(); driver.Quit(); }
private void createMapTileScreenshots(string nodeId, string latitude, string longitude) { String pathScreenshots = System.IO.Path.GetDirectoryName(System.AppDomain.CurrentDomain.BaseDirectory) + Path.DirectorySeparatorChar + "screenshots" + Path.DirectorySeparatorChar; Console.WriteLine("Screenshots Path: " + pathScreenshots); try { // setting for proxy //PhantomJSOptions phOptions = new PhantomJSOptions(); //phOptions.AddAdditionalCapability(CapabilityType.Proxy, "cache.itb.ac.id"); // hide cmd windows of phantomsjs var driverService = PhantomJSDriverService.CreateDefaultService(); driverService.HideCommandPromptWindow = true; // initiate phantomjs driver PhantomJSDriver phantom; phantom = new PhantomJSDriver(driverService); // setting the default timeout to 30 seconds phantom.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, 30)); string screenshotUrl = "http://localhost/bsts_routing/tilegen/v2/index.php?latitude=" + latitude + "&longitude=" + longitude; phantom.Navigate().GoToUrl(screenshotUrl); // grab the snapshot Screenshot sh = phantom.GetScreenshot(); TimeUtils timeUtils = new TimeUtils(); string fileName = nodeId + "_" + Convert.ToString(timeUtils.ToUnixTime(DateTime.Now)) + ".png"; sh.SaveAsFile(pathScreenshots + fileName, ImageFormat.Png); phantom.Quit(); } catch (Exception error) { Console.WriteLine(error.Message); } }
private void RenderScreen() { var img = _Driver.GetScreenshot(); Image RenderedImg = Image.FromStream(new System.IO.MemoryStream(img.AsByteArray)); this.Size = RenderedImg.Size; HelpMePictureBox.Image = RenderedImg; }
static void Main(string[] args) { driver = new PhantomJSDriver(); driver.Manage().Window.Maximize(); Console.WriteLine(driver.Manage().Window.Size); driver.Navigate().GoToUrl("https://google.com/"); driver.GetScreenshot().SaveAsFile("screenshot.png", ImageFormat.Png); driver.Quit(); Console.Read(); }
public string CreateStaticContent(string websiteKey, string url) { using (var driver = new PhantomJSDriver()) { SetupBrowserWindow(driver); string content; driver.Navigate().GoToUrl(url); content = driver.PageSource; _dataService.Save(websiteKey, url, content); Common common = new Common(); driver.GetScreenshot().SaveAsFile("c:\\Temp\\" + websiteKey + "\\" + common.GetFileName(url) + ".png", System.Drawing.Imaging.ImageFormat.Png); return(content); } }
public void SelectRegistrationTime(VisaDataSet.ClientDataRow dataRow) // state 16 { _logger.Trace($"Start SelectRegistrationTime. Error = {Error}."); OutData = string.Empty; FindElementWithChecking(By.Id(RegistryTime)).Click(); var scr = _driver.GetScreenshot(); var fileName = $"{dataRow.Name}_{dataRow.LastName}.jpg"; scr.SaveAsFile(fileName, ImageFormat.Jpeg); EmailManager.SendEmailWithMoneyRequest(dataRow.Email, dataRow.Password); EmailManager.SendEmailWithPhoto(fileName, dataRow.Email, dataRow.Password); _logger.Trace($"End SelectRegistrationTime. Error = {Error}"); }
/// <summary> /// GetSubImage /// </summary> /// <param name="driver"></param> /// <param name="iWebElement"></param> /// <returns></returns> private static Image GetSubImage(PhantomJSDriver driver, IWebElement iWebElement) { var location = iWebElement.Location; var x = location.X; var y = location.Y; var size = iWebElement.Size; var width = size.Width; var height = size.Height; var screenshot = driver.GetScreenshot(); //screenshot.SaveAsFile("c:/yuantu.png",ImageFormat.Png); var byteArray = screenshot.AsByteArray; var image = GetSubImage(byteArray, x, y, width, height); return(image); }
public void RunBotOnDOM() { RunBot.Instance.TestUnique(driver, wait); RunBot.Instance.DisplayResults(driver, wait); RunBot.Instance.SelectShoeSize(driver, wait); try { Screenshot sh = driver.GetScreenshot(); sh.SaveAsFile(@"C:\screenShots\Temp.jpg", ScreenshotImageFormat.Png); } catch (Exception) { Console.WriteLine("Screen Shot Failed..."); } }
public void CreateStaticContent(string websiteKey, List <SitemapUrl> urls) { using (var driver = new PhantomJSDriver()) { SetupBrowserWindow(driver); foreach (SitemapUrl url in urls) { if (Stop) { break; } string content; driver.Navigate().GoToUrl(url.Loc); if (url.WaitForElementId != null) { try// wait till ajax has finished loading or timeout occurs. { var element = new WebDriverWait(driver, TimeSpan.FromSeconds(url.WaitTime)).Until(ExpectedConditions.ElementExists(By.Id(url.WaitForElementId))); } catch { } } else { int count = 0; while (true) // Handle timeout somewhere { var ajaxIsComplete = (bool)(driver as IJavaScriptExecutor).ExecuteScript("return jQuery.active == 0"); if (ajaxIsComplete) { break; } Thread.Sleep(100); count++; } } content = driver.PageSource; _dataService.Save(websiteKey, url.Loc, content); Common common = new Common(); driver.GetScreenshot().SaveAsFile("c:\\Temp\\" + websiteKey + "\\" + common.GetFileName(url.Loc) + ".png", System.Drawing.Imaging.ImageFormat.Png); } } }
public void TakeScreenshotOfStep(int stepNo) { driver.GetScreenshot().SaveAsFile(this.GetType().Name + "-Step" + stepNo + ".png", ScreenshotImageFormat.Png); }
protected void ScreenShot() { Screenshot sh = driver.GetScreenshot(); sh.SaveAsFile(@"C:\Temp.jpg", ImageFormat.Png); }
private void takeScreenshot() { driver.GetScreenshot().SaveAsFile("image1.png", ScreenshotImageFormat.Png); }