コード例 #1
0
ファイル: Keywords.cs プロジェクト: exense/step-samples
        private void GoogleSearch(IWebDriver driver)
        {
            if (input["search"] != null)
            {
                if (driver == null)
                {
                    throw new Exception("Please first execute keyword \"Open Chome\" in order to have a driver available for this keyword");
                }

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

                //IWebElement searchInput = driver.FindElement(By.XPath("//input[@name='q']"));

                // Accept cookies and conditions
                driver.FindElement(By.XPath("//*[@id='L2AGLb']")).Click();

                IWebElement searchInput = driver.FindElement(By.Name("q"));

                String searchString = (string)input["search"];
                searchInput.SendKeys(searchString + Keys.Enter);

                IWebElement resultCountDiv = driver.FindElement(By.XPath("//div/nobr"));

                ICollection <IWebElement> resultHeaders = driver.FindElements(By.XPath("//div[@class='g']//h3"));
                foreach (IWebElement result in resultHeaders)
                {
                    output.Add(result.Text, result.FindElement(By.XPath("..//cite")).Text);
                }
                Screenshot ss = ((ITakesScreenshot)driver).GetScreenshot();

                string screenshot            = ss.AsBase64EncodedString;
                byte[] screenshotAsByteArray = ss.AsByteArray;
                output.AddAttachment(AttachmentHelper.GenerateAttachmentFromByteArray(screenshotAsByteArray, "screenshot.png"));
            }
            else
            {
                throw new Exception("Input parameter 'search' not defined");
            }
        }