Пример #1
0
        // get data from website using webdriver and save its contents into given IWebElement arguments.
        void fetchData(ref PhantomJSDriver driver, ref IWebElement myContent, ref IWebElement bidDetails, ref string[] enteredData)
        {
            driver = getWebBrowserDriverInit();
            string market = enteredData[0];
            string enteredDateFrom = enteredData[1];
            string enteredDateTo = enteredData[2];

            Exception tmpEx = null; // for possible exception recognition

            try
            {
                driver.Navigate().GoToUrl("https://kapalk1.mavir.hu/kapar/lt-publication.jsp?locale=en_GB");

                // TODO edit/delete if needed - this is not best approach (webpage can change)
                if (!(driver.Title.CompareTo("Kapar") == 0))
                {
                    driver.Quit();
                    throw new Exception("Error, webpage is not accessable or there is something wrong with your connection.");
                }

                driver.FindElementByXPath("/html/body/table/tbody/tr[2]/td/table/tbody/tr[2]/td[2]/div/table/tbody/tr/td[2]/input").Clear();

                driver.FindElementByXPath("/html/body/table/tbody/tr[2]/td/table/tbody/tr[2]/td[2]/div/table/tbody/tr/td[2]/input").SendKeys(enteredDateFrom); //SendKeys("12/4/2015");

                driver.FindElementByXPath("/html/body/table/tbody/tr[2]/td/table/tbody/tr[2]/td[2]/div/table/tbody/tr/td[4]/input").Clear();
                driver.FindElementByXPath("/html/body/table/tbody/tr[2]/td/table/tbody/tr[2]/td[2]/div/table/tbody/tr/td[4]/input").SendKeys(enteredDateTo); //SendKeys("12/10/2015");

                driver.FindElementByXPath("/html/body/table/tbody/tr[2]/td/table/tbody/tr[2]/td[2]/div/table/tbody/tr/td[6]/select").SendKeys(market); //SendKeys("All");

                driver.FindElementByXPath("/html/body/table/tbody/tr[2]/td/table/tbody/tr[2]/td[2]/div/table/tbody/tr/td[8]/button").Click();

                WebDriverWait waitForContent = new WebDriverWait(driver, TimeSpan.FromSeconds(60));
                myContent = waitForContent.Until<IWebElement>((d) =>
                {
                    return d.FindElement(By.XPath("/html/body/table/tbody/tr[3]/td/table"));
                });

                // xpath for 1st row in table
                driver.FindElementByXPath("/html/body/table/tbody/tr[3]/td/table/tbody/tr[2]/td[21]/a").Click();

                WebDriverWait waitForBidDetails = new WebDriverWait(driver, TimeSpan.FromSeconds(60));
                bidDetails = waitForContent.Until<IWebElement>((d) =>
                {
                    return d.FindElement(By.XPath("//html/body/div/div/table/tbody/tr[2]/td[2]/div/div/table/tbody/tr[1]/td/table"));
                });

            }
            catch (Exception e)
            {
                tmpEx = e;
            }

            if(tmpEx != null)
                throw new Exception(tmpEx.Message);
        }