static void Main(string[] args) { FirefoxOptions option = new FirefoxOptions(); ICapabilities cap = option.ToCapabilities(); FirefoxProfileManager mangage = new FirefoxProfileManager(); FirefoxProfile profile = mangage.GetProfile(mangage.ExistingProfiles[0]); IWebDriver driver = new FirefoxDriver(profile); driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(60)); driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10)); driver.Manage().Window.Maximize(); driver.Navigate().GoToUrl("https://www.baidu.com/"); IWebElement input = driver.FindElement(By.Id("kw")); input.SendKeys("shinetech"); IWebElement search = driver.FindElement(By.Id("su")); search.Click(); IWebElement shinetech = driver.FindElement(By.XPath("//div[@id='1']/h3/a")); if(shinetech!=null) { if(shinetech.Text.Contains("盛安德")) { Console.WriteLine("Find shinetech, test passed"); } else { Console.WriteLine("Cannot find Shinetech, test case failed"); } } else { Console.WriteLine("Cannot find Shinetech, test case failed"); } shinetech.Click(); driver.Dispose(); }
protected void Button4_Click(object sender, EventArgs e) { // Response.Write(marker_place); List<string> lst_zipscodes = new List<string>(); IGeocoder geocoder = new GoogleGeocoder() { }; DataSet ds = new DataSet("Sites_Collection"); string connection_string = ConfigurationManager.ConnectionStrings["UA_NAVConnectionString"].ConnectionString; SqlConnection conn = new SqlConnection(connection_string); WeatherReference.WeatherSoapClient weather = new WeatherReference.WeatherSoapClient("WeatherSoap"); // my source starting placeplace for (int i = 0; i < marker_place.Count; i++) { string source = marker_place[i]; string[] addr_string = source.Split(','); string[] zipcode = null; if (addr_string.Count() == 4) { zipcode = addr_string[2].Trim().Split(' '); source = addr_string[1] + "," + zipcode[0]; lst_zipscodes.Add(zipcode[1]); } else { continue; } IWebDriver driver = null; try { driver = new FirefoxDriver(); driver.Navigate().GoToUrl("http://www.nwf.org/naturefind.aspx"); driver.Manage().Window.Maximize(); var place_name = driver.FindElement(By.Id("content_0_txtBasicSearch")); place_name.Clear(); place_name.SendKeys(source); driver.FindElement(By.Id("content_0_btnSearchSites")).Click(); //driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10)); IWait<IWebDriver> wait = new OpenQA.Selenium.Support.UI.WebDriverWait(driver, TimeSpan.FromSeconds(15.00)); // IWait<IWebDriver> wait = null; wait.Until(driver1 => ((IJavaScriptExecutor)driver).ExecuteScript("return document.readyState").Equals("complete")); DataTable dt = new DataTable("Places_" + i); DataColumn place_Coulumn = new DataColumn("Scenic_Place_Name", Type.GetType("System.String")); DataColumn lat_Coulumn = new DataColumn("Latitude", Type.GetType("System.String")); DataColumn lng_Coulumn = new DataColumn("Longitude", Type.GetType("System.String")); DataColumn address_of_place = new DataColumn("Address", Type.GetType("System.String")); DataColumn Zipscode = new DataColumn("Zipcode", Type.GetType("System.String")); DataColumn weather_desc = new DataColumn("Weather", Type.GetType("System.String")); DataColumn temperature = new DataColumn("Temperature", Type.GetType("System.String")); DataColumn traffic = new DataColumn("Traffic", Type.GetType("System.String")); DataColumn safety = new DataColumn("Safety", Type.GetType("System.String")); dt.Columns.Add(place_Coulumn); dt.Columns.Add(lat_Coulumn); dt.Columns.Add(lng_Coulumn); dt.Columns.Add(address_of_place); dt.Columns.Add(Zipscode); dt.Columns.Add(weather_desc); dt.Columns.Add(temperature); dt.Columns.Add(traffic); dt.Columns.Add(safety); DataRow dr; int count1 = 0; try { wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("//div[@id='content_0_grdSiteList']//tr[@class='rgRow']//u"))); wait.Until(ExpectedConditions.ElementExists(By.XPath("//div[@id='content_0_grdSiteList']//tr[@class='rgRow']//u"))); IList<IWebElement> lst_places = driver.FindElements(By.XPath(".//div[@id='content_0_grdSiteList']//tr[@class='rgRow']//u")); if (lst_places == null) continue; int count = 0; foreach (IWebElement place in lst_places) { // if (count1!= -1) // { try { dr = dt.NewRow(); Thread.Sleep(200); dr["Scenic_Place_Name"] = place.Text; IEnumerable<Address> addresses = geocoder.Geocode(place.Text + "," + zipcode[0]); string place_addr = null; Location ltng = null; foreach (Address adr in addresses) { if (count == 0) { place_addr = adr.FormattedAddress; ltng = adr.Coordinates; dr["Address"] = place_addr; break; } } dr["Latitude"] = ltng.Latitude; dr["Longitude"] = ltng.Longitude; //tokenize place address string[] array = place_addr.Split(','); string[] waypoints = place_addr.Split(','); ///////******************* string zip = array[array.Length - 2]; string[] arr = zip.Trim().Split(' '); string webservicezip = null; if (arr.Length == 1) { dr["Zipcode"] = zipcode[1]; webservicezip = zipcode[1]; } else if (Regex.IsMatch(place_addr, @"\d")) { arr = zip.Trim().Split(' '); dr["Zipcode"] = arr[1].Trim(); webservicezip = arr[1].Trim(); } //weather update WeatherReference.WeatherReturn weather_of_place = weather.GetCityWeatherByZIP(webservicezip); // arr[1].Trim() dr["Weather"] = weather_of_place.Description; dr["Temperature"] = weather_of_place.Temperature; Random rnd = new Random(); dr["Traffic"] = rnd.Next(2, 5); dr["Safety"] = rnd.Next(60, 100); dt.Rows.Add(dr); //break; } catch (Exception ex) { Console.WriteLine(ex); continue; } } } finally { ds.Tables.Add(dt); } } finally { driver.Close(); driver.Dispose(); } } WriteDataToDATABASE(ds); string[] scenic_places = CreateListScenicPlaces(); // DrawScenicDirection(); foreach (string s in scenic_places) { ClientScript.RegisterArrayDeclaration("scenic_places", "\"" + s + "\""); } ClientScript.RegisterStartupScript(Page.GetType(), "Scenic", "scenic_route();", true); }
static int Main(string[] args) { string usrName = ""; string usrPasswd = ""; IWebDriver driver = new FirefoxDriver(); //simple usage if(args.Length < 1) { Console.WriteLine("usage: <username> <passwd>"); driver.Dispose(); return(0); } else if ((args.Length > 0) && (args[0].ToString().ToLower() == "help")) { Console.WriteLine("usage: <username> <passwd>"); driver.Dispose(); return (0); } else if (args.Length == 2) { usrName = args[0]; usrPasswd = args[1]; } else { Console.WriteLine("usage: <username> <passwd>"); driver.Dispose(); return (0); } Console.WriteLine("Initializing..."); driver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, 30)); //Make the findelements try finding for up to 30 seconds before failing--helps to resolve some timing issues driver.Navigate().GoToUrl(url); //checks Console.WriteLine("Validating site..."); if(validateBasePage(driver)) { Console.WriteLine("\t->Pass"); } else { Console.WriteLine("\t->Fail"); } Console.WriteLine("Logging in..."); try { if (logIn(driver, usrName, usrPasswd)) { Console.WriteLine("\t->Pass"); } else { Console.WriteLine("\t->Fail"); return (0); } } catch { } System.Threading.Thread.Sleep(500); Console.WriteLine("Validating Page after login"); try { if (validatePostLoginPage(driver)) { Console.WriteLine("\t->Pass"); } else { Console.WriteLine("\t->Fail"); return (0); } } catch (Exception) { driver.Dispose(); return (0); } Console.WriteLine("Navigating to Profile link"); try { if (LoadProfile_Link(driver)) { Console.WriteLine("\t->Pass"); } else { Console.WriteLine("\t->Fail"); return (0); } } catch { Console.WriteLine("\t->Fail"); } driver.Dispose(); return (0); }