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(); }
protected void Type(string path, string pathType, string value) { if (pathType == "id") { IWebElement element = driver.FindElementById(path); element.SendKeys(value); TestCase.Log("Entered " + value + " at element with id=" + path); } if (pathType == "name") { IWebElement element = driver.FindElementByName(path); element.SendKeys(value); TestCase.Log("Entered " + value + " at element with name=" + path); } if (pathType == "class") { IWebElement element = driver.FindElementByClassName(path); element.SendKeys(value); TestCase.Log("Entered " + value + " at element with class=" + path); } if (pathType == "xpath") { IWebElement element = driver.FindElementByXPath(path); element.SendKeys(value); TestCase.Log("Entered " + value + " at element with xpath=" + path); } }
public static int Count(PhantomJSDriver driver, string xpath) { string str = ""; try { str = driver.FindElementByXPath(xpath).Text .Replace(",", "") .Replace(" entries", ""); } catch { return(0); } int to_sub = 0; while (char.IsNumber(str[str.Length - to_sub - 1])) { to_sub++; } return(int.Parse(str.Substring(str.Length - to_sub))); }
public void Click(string xpath) { wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath(xpath))); browser.FindElementByXPath(xpath).Click(); }
public bool IsChecked(string label) { return(_driver.FindElementByXPath( string.Format("//input[following-sibling::label[text()=\"{0}\"]]", label)).Selected); }
//Get Bet Types and scrape the shit out of them public void betTypes() { takeScreenshot(); string a = "//div[@id='bettype-tabs']//li[@style='display: block;']//a"; // string a = "//div[@id='bettype-tabs']//a"; var activeLink = driver.FindElementByXPath("//div[@id='bettype-tabs']//li[@class=' active']").Text; switchBettype(activeLink); var hidden = "//div[@id='bettype-tabs']//li[14]//a"; var li = driver.FindElementsByXPath(a).ToList(); var hid = driver.FindElementsByXPath(hidden).ToList(); string js; Bettypes = new Dictionary <string, string>(); foreach (var link in li) { js = link.GetAttribute("onmousedown"); js = js.Split(';')[0]; Bettypes[link.Text] = js; } foreach (var link in hid) { try { js = link.GetAttribute("onmousedown"); js = js.Split(';')[1]; Bettypes[link.Text] = js; } catch (Exception w) { } } foreach (var dict in Bettypes) { try { switchBettype(dict); } catch (Exception e) { Console.WriteLine("/////////////////LOG: Exception retrieving " + dict.Key + " From" + url); } } }
public void Execute(IUBotStudio ubotStudio, Dictionary<string, string> parameters) { try { var fbemail = parameters["fb email"]; var fbpassword = parameters["fb password"]; //var useragent = parameters["user agent"]; var proxy = parameters["Proxy"]; _driverService = PhantomJSDriverService.CreateDefaultService(); _driverService.HideCommandPromptWindow = true; if (proxy != string.Empty) { var pproxy = new Webdriver.Proxy(); if (proxy.Contains("@")) { var sproxy = proxy.Split('@'); var cred = sproxy[0].Split(':'); pproxy.HttpProxy = string.Format(sproxy[1]); _driverService.ProxyType = "http"; _driverService.Proxy = pproxy.HttpProxy; _driverService.ProxyAuthentication = cred[0] + ":" + cred[1]; } else { pproxy.HttpProxy = string.Format(proxy); _driverService.ProxyType = "http"; _driverService.Proxy = pproxy.HttpProxy; } } _phantom = new PhantomJSDriver(_driverService); _phantom.Navigate().GoToUrl("http://www.facebook.com"); var element1 = _phantom.FindElementByXPath("//input[@name=\"email\"]"); element1.SendKeys(fbemail); element1 = _phantom.FindElementByXPath("//input[@name=\"pass\"]"); element1.SendKeys(fbpassword); element1 = _phantom.FindElementByXPath("//label[@id=\"loginbutton\"]/input"); element1.Click(); _phantom.Navigate().GoToUrl("https://developers.facebook.com/tools/explorer/"); element1 = _phantom.FindElementByXPath("//input[contains(@placeholder,\"Access Token\")]"); _returnValue = element1.GetAttribute("value"); } finally { _phantom.Quit(); } }