public void SeleniumAPI_Demo4()
        {
            _output.WriteLine("Step 01 : 启动浏览器并打开博客园首页。");
            IWebDriver driver = new FirefoxDriver();
            driver.Url = "http://www.cnblogs.com";

            _output.WriteLine("Step 02 : 寻找需要操作的页面元素。");
            var divText = driver.FindElement(By.Id("site_nav_top"));            
            var point = divText.Location;
            var width = int.Parse(divText.GetCssValue("width").Replace("px", string.Empty));
            
            _output.WriteLine("Step 03 : 选中文本信息。");
            var action = new Actions(driver);
            action
                .MoveByOffset(point.X, point.Y)         //移动鼠标到文本开头
                .ClickAndHold()                         //按下鼠标    
                .MoveByOffset(point.X + width, point.Y) //移动鼠标到文本结束
                .Release()                              //释放鼠标
                .Build()
                .Perform();

            System.Threading.Thread.Sleep(5000);
            _output.WriteLine("Step 04 : 关闭浏览器。");
            driver.Close();
        }
예제 #2
0
 public void PostToBlog()
 {
     IWebDriver browser = new FirefoxDriver();
     browser.Navigate().GoToUrl("http://tumblr.com/login");
     IWebElement email = browser.FindElement(By.Id("signup_determine_email"));
     email.SendKeys("*****@*****.**");
     IWebElement verifyButton = browser.FindElement(By.Id("signup_forms_submit"));
     verifyButton.Click();
     browser.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5));
     IWebElement password = browser.FindElement(By.Id("signup_password"));
     password.SendKeys("******");
     IWebElement loginButton = browser.FindElement(By.Id("signup_forms_submit"));
     loginButton.Click();
     IWebElement textIcon = browser.FindElement(By.ClassName("icon_post_text"));
     textIcon.Click();
     IWebElement postTitle = browser.FindElement(By.ClassName("editor-plaintext"));
     postTitle.SendKeys("c# selenium");
     IWebElement postBody = browser.FindElement(By.ClassName("editor-richtext"));
     postBody.SendKeys("this is a c# with selenium test");
     IWebElement createPost = browser.FindElement(By.ClassName("create_post_button"));
     createPost.Click();
     //TearDown
     IWebElement postSettings = browser.FindElement(By.ClassName("post_control_menu"));
     postSettings.Click();
     IWebElement postDelete = browser.FindElement(By.ClassName("delete"));
     postDelete.Click();
     IWebElement okButton = browser.FindElement(By.ClassName("btn_1"));
     okButton.Click();
     IWebElement accountButton = browser.FindElement(By.ClassName("icon_user_settings"));
     browser.Close();
 }
        public List<FootballItem> Parse() {
            List<FootballItem> res = new List<FootballItem>();

            IWebDriver driver = new FirefoxDriver();

            driver.Navigate().GoToUrl("https://www.marathonbet.com/su/popular/Football/?menu=true#");
            ReadOnlyCollection<IWebElement> main = driver.FindElements(By.ClassName("sport-category-container"));
            Debug.Assert(main.Count==1);
            ReadOnlyCollection<IWebElement> containers = main[0].FindElements(By.ClassName("category-container"));
            foreach (IWebElement container in containers) {
                ReadOnlyCollection<IWebElement> tables = container.FindElements(By.ClassName("foot-market"));
                Debug.Assert(tables.Count==1);
                ReadOnlyCollection<IWebElement> tbodys = tables[0].FindElements(By.XPath(".//tbody[@data-event-name]"));
                ParseTBody(tbodys, res);
            }

            /*
            WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
            wait.Until((d) => { return d.Title.ToLower().StartsWith("cheese"); });
            */
            driver.Close();
            driver.Quit();

            return res;
        }
예제 #4
0
 private void CloseSafely(FirefoxDriver browser)
 {
     try
     {
         browser.Close();
     }
     catch (Exception)
     {
     }
 }
        public void TestFlowControl_Demo1()
        {
            IWebDriver driver = new FirefoxDriver();   
            // 1. 隐式的等待 同步测试
            driver.Manage().Timeouts()
                .ImplicitlyWait(TimeSpan.FromSeconds(10))
                .SetPageLoadTimeout(TimeSpan.FromSeconds(10))
                .SetScriptTimeout(TimeSpan.FromSeconds(10));

            driver.Close();
        }
예제 #6
0
파일: CodedUITest1.cs 프로젝트: juni-j/arf
        public void SearchForCuteSealsGoogle()
        {
            IWebDriver driver = new FirefoxDriver();

            driver.Navigate().GoToUrl("http://www.google.com");
            driver.Manage().Window.Maximize();

            IWebElement searchInput = driver.FindElement(By.Id("gbqfq"));
            searchInput.SendKeys("cute seals");
            searchInput.SendKeys(OpenQA.Selenium.Keys.Enter);
            driver.Close();
        }
예제 #7
0
파일: Program.cs 프로젝트: juni-j/arf
        static void Main(string[] args)
        {
            IWebDriver driver = new FirefoxDriver();

            driver.Navigate().GoToUrl("http://www.bing.com");
            driver.Manage().Window.Maximize();

            IWebElement searchInput = driver.FindElement(By.Id("sb_form_q"));
            searchInput.SendKeys("cute seals");
            searchInput.SendKeys(Keys.Enter);
            driver.Close();
        }
예제 #8
0
        public void XpathTest()
        {
            IWebDriver driver = new FirefoxDriver();
            driver.Navigate().GoToUrl("http://www.thetestroom.com/webapp");

            // locate the contact link using xpath and click on it
            driver.FindElement(By.XPath("//a[contains(@id, 'contact_link')]")).Click();

            // Now we are on the "Contact" page
            // locate the name input on "Contact" page using xpath and enter text into it
            driver.FindElement(By.XPath("//input[contains(@name, 'name_field')]")).SendKeys("test name");

            driver.Close();
        }
예제 #9
0
        static void Main(string[] args)
        {
            IWebDriver driver = new FirefoxDriver();

            driver.Navigate().GoToUrl("http://bing.com/");
            driver.Manage().Window.Maximize();

            IWebElement sString = driver.FindElement(By.Id("sb_form_q"));
            sString.SendKeys("Hello world");

            IWebElement sSubmit = driver.FindElement(By.Id("sb_form_go"));
            sSubmit.Click();

            driver.Close();
        }
        public void SearchGoogle()
        {
            IWebDriver Browser = new FirefoxDriver();

            GoogleLanding landing = new GoogleLanding(Browser);
            landing.Navigate("http://www.google.com");
            landing.SendKeys_SearchBar("Sting Ray");
            landing.Click_SearchButton();

            Thread.Sleep(5000);
            landing.Click_Result(2);
            Thread.Sleep(5000);

            Assert.AreEqual(Browser.Url, "http://www.autodesk.com/products/stingray/overview");

            Browser.Close();
        }
        public void SeleniumAPI_Demo1()
        {
            _output.WriteLine("Step 01 : 启动浏览器并打开博客园首页。");
            IWebDriver driver = new FirefoxDriver();
            driver.Url = "http://www.cnblogs.com";

            _output.WriteLine("Step 02 : 寻找需要检查的页面元素。");
            var lnkHome = driver.FindElement(By.XPath(".//ul[@class='post_nav_block']/li[1]/a"));
            var value = lnkHome.GetAttribute("class");
            lnkHome.GetCssValue("font-family");
            lnkHome.GetCssValue("color");
            
            _output.WriteLine(string.Format("导航内栏内容:{0}", lnkHome.Text));

            _output.WriteLine("Step 04 : 关闭浏览器。");
            driver.Close();
        }
예제 #12
0
 public void TestMethod1()
 {
     var driver = new FirefoxDriver();
     try
     {
         driver.Navigate().GoToUrl("http://docs.seleniumhq.org/oops");
         driver.FindElement(By.Id("q")).Click();
         driver.Keyboard.SendKeys("Hello World!");
         driver.Keyboard.PressKey(Keys.Enter);
     }
     catch (Exception e)
     {
         var ss = driver.GetScreenshot(); 
         ss.SaveAsFile("failed-test-case.png", ImageFormat.Png);
         driver.Close();
         throw;
     }
 }
예제 #13
0
        public static void TestDriver()
        {
            var url = "https://jerdine.smartbizonline.com";

            IWebDriver driver = new FirefoxDriver();

            // Navigate to url
            driver.Navigate().GoToUrl(url);

            // Login
            driver.FindElement(By.Id("txtUserName")).Clear();
            driver.FindElement(By.Id("txtUserName")).SendKeys("*****@*****.**");
            driver.FindElement(By.Id("Password")).Clear();
            driver.FindElement(By.Id("Password")).SendKeys("1234");
            driver.FindElement(By.XPath("//button[text()='Login']")).Click();

            driver.Close();
        }
예제 #14
0
        public void CoreObject_Demo1()
        {
            _output.WriteLine("Step 01 : 启动浏览器并打开博客园首页。");
            IWebDriver driver = new FirefoxDriver();
            driver.Url = "http://www.cnblogs.com";
            driver.Manage().Window.Maximize();

            _output.WriteLine("Step 02 : 获取并输出部分页面信息。");
            _output.WriteLine(string.Format("Current window handle: {0}", driver.CurrentWindowHandle));
            _output.WriteLine(string.Format("Window handle count: {0}", driver.WindowHandles.Count));
            _output.WriteLine(string.Format("Current window title: {0}", driver.Title));

            _output.WriteLine("Step 03 : 验证博客园站点的 Title 是否正确。");
            Assert.Equal<string>("博客园 - 开发者的网上家园", driver.Title);

            _output.WriteLine("Step 04 : 关闭当前页面。");
            driver.Close();
        }
        static void Main(string[] args)
        {
            IWebDriver driver = new FirefoxDriver();
            driver.Navigate().GoToUrl("http://www.rmv.de");
            //driver.Navigate().GoToUrl(baseURL + "/");
            driver.FindElement(By.Id("myname")).Clear();
            driver.FindElement(By.Id("myname")).SendKeys("*****@*****.**");
            driver.FindElement(By.Id("mypw")).Clear();
            driver.FindElement(By.Id("mypw")).SendKeys("Keith)98");
            //driver.FindElement(By.CssSelector("button.a11y-focus")).Click();
            driver.FindElement(By.XPath("//*[text()=\"Login\"]")).Click();
            driver.FindElement(By.Id("searchbar")).Click();
            driver.FindElement(By.Id("searchbar")).Clear();
            driver.FindElement(By.Id("searchbar")).SendKeys("hamburg");
            driver.FindElement(By.XPath("//*[text()=\"Suchen\"]")).Click();
            driver.FindElement(By.LinkText("Logout")).Click();

            driver.Close();
        }
예제 #16
0
        static void Main(string[] args)
        {
            //Create the reference for our browser
            IWebDriver driver = new FirefoxDriver();

            driver.Navigate().GoToUrl(@"D:\Dropbox\ValtechProjects\WEB\Calculator\index.html");

            //Find the element
            IWebElement btn_0 = driver.FindElement(By.Name("0"));
            IWebElement btn_1 = driver.FindElement(By.Name("1"));
            IWebElement btn_2 = driver.FindElement(By.Name("2"));
            IWebElement btn_3 = driver.FindElement(By.Name("3"));
            IWebElement btn_4 = driver.FindElement(By.Name("4"));
            IWebElement btn_5 = driver.FindElement(By.Name("5"));
            IWebElement btn_6 = driver.FindElement(By.Name("6"));
            IWebElement btn_7 = driver.FindElement(By.Name("7"));
            IWebElement btn_8 = driver.FindElement(By.Name("8"));
            IWebElement btn_9 = driver.FindElement(By.Name("9"));
            IWebElement btn_minus = driver.FindElement(By.Name("-"));
            IWebElement btn_plus = driver.FindElement(By.Name("+"));
            IWebElement btn_divide = driver.FindElement(By.Name("/"));
            IWebElement btn_multi = driver.FindElement(By.Name("*"));
            IWebElement btn_equal = driver.FindElement(By.Name("="));
            IWebElement btn_clear = driver.FindElement(By.Name("c"));
            
            btn_0.Click();
            btn_1.Click();
            btn_2.Click();
            btn_3.Click();
            btn_4.Click();
            btn_5.Click();
            btn_6.Click();
            btn_7.Click();
            btn_8.Click();
            btn_9.Click();
            btn_divide.Click();
            btn_minus.Click();
            btn_multi.Click();
            btn_plus.Click();
            btn_equal.Click();
            btn_clear.Click();
            driver.Close();
        }
예제 #17
0
        public void Execute()
        {
            String outputPath = localDesktop + String.Format(@"\WebTest\{0}_{1:yyyy-MM-dd_hh-mm-ss-tt}", "firefox", DateTime.Now);
            
            IWebDriver driver_firefox = new FirefoxDriver();
            AllPagesFound(driver_firefox, "firefox", outputPath);
            RunInputSuite(driver_firefox, "firefox", outputPath);
            driver_firefox.Close();
            
            outputPath = localDesktop + String.Format(@"\WebTest\{0}_{1:yyyy-MM-dd_hh-mm-ss-tt}", "chrome", DateTime.Now);
            IWebDriver driver_chrome = new ChromeDriver(chromeDriverPath);
            RunInputSuite(driver_chrome, "chrome", outputPath);
            driver_chrome.Close();

            //disabling IE, machine may need registry edits to get it to work
            /*
            outputPath = localDesktop + String.Format(@"\WebTest\{0}_{1:yyyy-MM-dd_hh-mm-ss-tt}", "explorer", DateTime.Now);
            IWebDriver driver_explorer = new InternetExplorerDriver(IEDriverPath);
            RunInputSuite(driver_explorer, "chrome", outputPath);
            driver_explorer.Close();*/
        }
예제 #18
0
        public void CssTest()
        {
            IWebDriver driver = new FirefoxDriver();
            driver.Navigate().GoToUrl("http://www.thetestroom.com/webapp");

            // By id
            driver.FindElement(By.CssSelector("#contact_link")).Click();

            // On "Contact" page
            // node or tag
            Console.WriteLine(driver.FindElement(By.CssSelector("p")).Text);

            // By class
            driver.FindElement(By.CssSelector(".home")).Click();

            // On "Home" page
            // Attribute expression
            driver.FindElement(By.CssSelector("[href='adoption.html']")).Click();

            // Now on "Adoption" page
            driver.Close();
        }
예제 #19
0
        public void LoadPage()
        {
            var driver = new FirefoxDriver();
            driver.Url = "http://www.reallysimpleabtesting.co.uk//";

            var element = driver.FindElementByClassName("test");

            var message = element.Text;

            Console.WriteLine(message);

            if (message.Contains("call to action"))
            {
                if (Chance.FlipACoin())
                {
                    var link = driver.FindElementById("calltoaction");
                    link.Click();
                }
            }

            driver.Close();
        }
예제 #20
0
        public void CheckNavBar_GetElement()
        {
            _output.WriteLine("Step 01 : 启动浏览器并打开博客园首页。");
            IWebDriver driver = new FirefoxDriver();
            driver.Url = "http://www.cnblogs.com";

            _output.WriteLine("Step 02 : 寻找需要检查的页面元素。");
            var divMain = driver.FindElement(By.Id("main"));
            var lnkHome = driver.FindElement(By.XPath(".//ul[@class='post_nav_block']/li[1]/a"));
            var lnkEssence = driver.FindElement(By.XPath(".//ul[@class='post_nav_block']/li[2]/a"));
            var lnkCandidate = driver.FindElement(By.XPath(".//ul[@class='post_nav_block']/li[3]/a"));
            var lnkNews = driver.FindElement(By.XPath(".//ul[@class='post_nav_block']/li[4]/a"));

            _output.WriteLine("Step 03 : 检查导航条文字信息。");
            Assert.Equal<string>("首页", lnkHome.Text);
            Assert.Equal<string>("精华", lnkEssence.Text);
            Assert.Equal<string>("候选", lnkCandidate.Text);
            Assert.Equal<string>("新闻", lnkNews.Text);

            _output.WriteLine("Step 04 : 关闭浏览器。");
            driver.Close();
        }
예제 #21
0
        public void shouldAllLinkLeadSomewhere()
        {
            IWebDriver driver = new FirefoxDriver();
            driver.Navigate().GoToUrl("http://www.theguardian.com");
            var mainPage = new MainEntryPage(driver);
            listoflinks = mainPage.GetLinks (driver);

            for (int n = 0; n < listoflinks.Count; n++) {

                Console.WriteLine(listoflinks[n].Text);
                var beforeWindow = driver.CurrentWindowHandle;

                if (driver.FindElement(By.LinkText(listoflinks[n].Text)).Displayed && listoflinks[n].Text != "Sign in"){

                    Console.WriteLine("Found link: " + listoflinks[n].Text);
                    driver.FindElement(By.LinkText(listoflinks[n].Text)).SendKeys(Keys.Shift + Keys.Return);

                    foreach (string handle in driver.WindowHandles)
                    {
                        if (handle != beforeWindow)
                        {
                            driver.SwitchTo().Window(handle);
                            break;
                        }
                    }
                    Console.WriteLine("UJ: " + driver.Url);
                    driver.Close();
                    driver.SwitchTo().Window(beforeWindow);
                    Console.WriteLine("REGI: " + driver.Url);
                }
                else
                {

                    Console.WriteLine("NotFound link: " + listoflinks[n].Text);
                }

                //driver.Navigate().Back();
            }
        }
예제 #22
0
        public void CheckNavBar_GetElements()
        {
            _output.WriteLine("Step 00 : 准备测试数据。");
            var testDatas = new List<string>() { "首页", "精华", "候选", "新闻" };      //准备测试数据

            _output.WriteLine("Step 01 : 启动浏览器并打开博客园首页。");
            IWebDriver driver = new FirefoxDriver();
            driver.Url = "http://www.cnblogs.com";

            _output.WriteLine("Step 02 : 寻找需要检查的页面元素。");
            var divMain = driver.FindElement(By.Id("main"));
            var lnkNavList = driver.FindElements(By.XPath(".//ul[@class='post_nav_block']/li[1]/a"));

            _output.WriteLine("Step 03 : 检查导航条文字信息。");
            for (var i = 0; i < lnkNavList.Count; i++)
            {
                Assert.Equal<string>(testDatas[i], lnkNavList[i].Text);
            }

            _output.WriteLine("Step 04 : 关闭浏览器。");
            driver.Close();
        }
예제 #23
0
        static void Main(string[] args)
        {
            IWebDriver driver = new FirefoxDriver();

            driver.Navigate().GoToUrl("http://themoneyconverter.com/");

            driver.Manage().Window.Maximize();

            IWebElement valueInput = driver.FindElement(By.Id("ta"));
            IWebElement fromInput = driver.FindElement(By.Id("df"));
            IWebElement toInput = driver.FindElement(By.Id("dt"));
            IWebElement resultArea = driver.FindElement(By.Id("ratebox"));

            const string valorDigitado = "1",
                         valorEsperado = "BRL/USD = 3.7056",
                         fromValue = "USD - United States Dollar",
                         toValue = "BRL - Brazilian Real";

            valueInput.SendKeys(valorDigitado);

            var selectTo = new SelectElement(fromInput);
            var selectFrom = new SelectElement(toInput);

            selectTo.SelectByText(fromValue);
            selectFrom.SelectByText(toValue);

            Thread.Sleep(900);

            if (resultArea.GetAttribute("value") == valorEsperado)
                Console.WriteLine("Deu certo");
            else
                Console.WriteLine("Não deu certo");

            driver.Close();

            Console.ReadKey();
        }
        /// <summary>
        /// Shortens a URL using the Google URL shortener, Selenium, and Firefox browser.
        /// </summary>
        /// <param name="longUrl">A URL to be passed to the shortening service.</param>
        /// <returns>A short version of the URL.</returns>
        private string ShortenUrl(string longUrl)
        {
            const string shortenerUi = "https://goo.gl/";
            if (longUrl == null)
            {
                throw new ArgumentNullException("longUrl");
            }

            // Use FireFox to get the page.
            IWebDriver driver = new FirefoxDriver();
            driver.Navigate().GoToUrl(shortenerUi);
            // <input name="is_logged_in" id="is_logged_in" value="false" type="hidden">
            IWebElement userLoggedIn = driver.FindElement(By.Id("is_logged_in"));
            if (userLoggedIn.GetAttribute("value") == "false")
            {
                this.GoogleSignIn(driver);
            }

            // Get the page elements for the input box and its submit button.
            // <input tabindex="1" id="shortenerInputText" class="IXTYPID-x-a IXTYPID-b-a IXTYPID-d-b IXTYPID-r-b" type="text">
            IWebElement shortenerInputText = driver.FindElement(By.Id("shortenerInputText"));
            // <div aria-disabled="false" role="button" aria-labelledby="gwt-uid-33" id="shortenerSubmitButton" tabindex="1" class="IXTYPID-d-a IXTYPID-w-a IXTYPID-b-a IXTYPID-r-g"><span class="IXTYPID-b-a IXTYPID-w-f"></span> <span class="IXTYPID-b-a IXTYPID-w-h">Shorten URL</span></div>
            IWebElement shortenerSubmitButton = driver.FindElement(By.Id("shortenerSubmitButton"));
            System.Threading.Thread.Sleep(1000);
            shortenerInputText.SendKeys(longUrl);
            shortenerSubmitButton.Click();

            // Wait for the element to be populated
            WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30));
            wait.Until((d) => { return d.FindElement(By.ClassName("IXTYPID-p-b")); });

            // <input tabindex="2" class="IXTYPID-p-b" readonly="readonly" value="" type="text">
            IWebElement shortenedUrl = driver.FindElement(By.ClassName("IXTYPID-p-b"));
            string urlValue = shortenedUrl.GetAttribute("value");
            driver.Close();
            return urlValue;
        }
예제 #25
0
        public void StartScreenshotting(object parameters)
        {
            var parameter = parameters as object[];
            InstanceInfo instanceInfo = parameter[0] as InstanceInfo;
            DataTable urls = parameter[1] as DataTable;

            try
            {
                Log("Starting firefox...");
                FirefoxProfile ffProfile = new FirefoxProfile();
                JavaScriptError.AddExtension(ffProfile);

                using (var browser = new FirefoxDriver(ffProfile))
                {
                    string targetDirectory = CreateTargetDirectory(instanceInfo);
                    List<JavaScriptError> jsErrors = new List<JavaScriptError>();

                    for (int i = 0; i < urls.Rows.Count; i++)
                    {
                        try
                        {
                            Guid nodeGuid = (Guid)urls.Rows[i]["NodeGUID"];
                            Uri url = new Uri(instanceInfo.Uri, "getdoc/" + nodeGuid);

                            Log("Screenshotting [{0}/{1}]: {2}", i, urls.Rows.Count, nodeGuid);

                            browser.Navigate().GoToUrl(url);
                            string fileName = GetFileName(targetDirectory, browser.Url);
                            browser.GetScreenshot()
                                .SaveAsFile(fileName, ImageFormat.Jpeg);

                            jsErrors.AddRange(JavaScriptError.ReadErrors(browser));
                        }
                        catch (Exception e)
                        {
                            Log("Exception: {0}", e.Message);
                        }
                    }

                    SaveJavaScriptErrorsToFile(jsErrors, targetDirectory);
                    Log("Screenshotting finished.");
                    browser.Close();
                }
            }
            catch (WebDriverException ex)
            {
                // If the exception occurs, it's most probably because Firefox is not installed.
                Console.WriteLine(ex.Message);
            }
        }
        public void SeleniumAPI_Demo3()
        {
            _output.WriteLine("Step 01 : 启动浏览器并打开博客园首页。");
            IWebDriver driver = new FirefoxDriver();
            driver.Url = "http://www.cnblogs.com";

            _output.WriteLine("Step 02 : 寻找需要操作的页面元素。");
            var txtSearch = driver.FindElement(By.Id("zzk_q"));
            var btnSearch = driver.FindElement(By.XPath(".//input[@type='button' and @value='找找看']"));

            _output.WriteLine("Step 03 : 输入查询文本");
            txtSearch.SendKeys("小北De编程手记");

            _output.WriteLine("Step 04 : 点击查询");
            btnSearch.Click();

            System.Threading.Thread.Sleep(5000);

            _output.WriteLine("Step 05 : 关闭浏览器。");
            driver.Close();
        }
예제 #27
0
        private static void Main(string[] args)
        {
            // creates a session that uses my Firefox profile.

            FirefoxProfileManager profileManager = new FirefoxProfileManager();
            FirefoxProfile profile = profileManager.GetProfile("Ryan");
            IWebDriver driver = new FirefoxDriver(profile);

            driver.Url = "http://www.google.com";

            var searchBox = driver.FindElement(By.Id("lst-ib"));
            //Looks for the correct site.

            searchBox.SendKeys("animefreak.tv");

            searchBox.Submit();

            var searchButton = driver.FindElement(By.ClassName("lsb"));
            searchButton.Click();
            System.Threading.Thread.Sleep(1000);
            // Click on the first result for AnimeFreak.tv
            driver.FindElement(By.XPath("id('rso')/div/div[1]/div/h3/a")).Click();

            System.Threading.Thread.Sleep(1000);
            driver.FindElement(By.XPath("id('submenu')/ul/li[3]/a")).Click();
            System.Threading.Thread.Sleep(1000);

            //Selects "O" from the list
            driver.FindElement(By.XPath("id('primary')/div/div[3]/div[1]/div/div/span[20]/a")).Click();
            System.Threading.Thread.Sleep(1000);
            //Goes to OnePiece

             driver.FindElement(By.XPath(".//*[@id='primary']/div/div[3]/div[2]/table/tbody/tr[9]/td/a")).Click();
            System.Threading.Thread.Sleep(1000);

            //Goes to Episode 422
            //driver.FindElement(By.XPath("id('page')/div[5]/div[2]/div[2]/div/ul/li[418]/a")).Click();
            driver.FindElement(By.XPath("id('page')/div[5]/div[2]/div[2]/div/ul/li[1]/a")).Click();
            System.Threading.Thread.Sleep(1000);

            do
            {
                if (!driver.FindElement(By.XPath("id('primary')/div/div[3]/div/a[2]")).Enabled)
                {

                }
                driver.FindElement(By.ClassName("page-next")).Click();
            } while (driver.FindElement(By.XPath("id('primary')/div/div[3]/div/a[2]")).Enabled);

             driver.Close();
        }
        public void SeleniumAPI_Demo6()
        {
            _output.WriteLine("Step 01 : 启动浏览器并打开博客园首页。");
            IWebDriver driver = new FirefoxDriver();
            driver.Url = "http://www.cnblogs.com";

            _output.WriteLine("Step 02 : 寻找需要操作的页面元素。");
            var txtSearch = driver.FindElement(By.Id("zzk_q"));
            var btnSearch = driver.FindElement(By.XPath(".//input[@type='button' and @value='找找看']"));

            _output.WriteLine("Step 03 : 输入查询文本&点击查询");
            txtSearch.SendKeys("小北De编程手记");
            btnSearch.Click();
            
            _output.WriteLine("Step 04 : 截屏");
            var takesScreenshot = (ITakesScreenshot)driver;
            var screenshot = takesScreenshot.GetScreenshot();
            screenshot.SaveAsFile("screenshot.png", ImageFormat.Png);

            _output.WriteLine("Step 05 : 关闭浏览器。");
            driver.Close();
        }
        public void SeleniumAPI_Demo5()
        {
            _output.WriteLine("Step 01 : 启动浏览器并打开某个网站。");
            IWebDriver driver = new FirefoxDriver();
            driver.Url = "http://www.xxx.com";

            _output.WriteLine("Step 02 : 寻找需要操作的页面元素。");
            var dllDom = (SelectElement)driver.FindElement(By.Id("selectDomId"));
            var isMultiple = dllDom.IsMultiple;
            var option = dllDom.SelectedOption;
            dllDom.SelectByIndex(1);
            dllDom.SelectByText("Text");
            dllDom.SelectByValue("Value");

            //单选按钮
            var radioA = driver.FindElement(By.Id("radioA_Id"));
            var radioB = driver.FindElement(By.Id("radioB_Id"));
            radioB.Click();
            var isSelected = radioA.Selected;

            _output.WriteLine("Step 03 : 关闭浏览器。");
            driver.Close();
        }
    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);
    }