Пример #1
0
 private static bool ChangePage(ChromeDriver driver)
 {
     try
     {
         _pageCounter++;
         Console.WriteLine(_currentUrl + "?page=" + _pageCounter);
         driver.Navigate().GoToUrl(_currentUrl + "?page=" + _pageCounter);
         driver.FindElementByXPath($"//*[@id='body-container']/div[3]/div/div[5]/span[{_pageCounter}]/a");
         return(true);
     }
     catch
     {
         Console.WriteLine("Change page exception");
         return(false);
     }
 }
Пример #2
0
        public void LogIn()
        {
            using (var driver = new ChromeDriver())
            {
                driver.Navigate().GoToUrl(URL);

                var loginButton = driver.FindElementByXPath("//a[text() = 'Sign in']");
                loginButton.Click();

                var userNameField     = driver.FindElementById("login_field");
                var userPasswordField = driver.FindElementById("password");

                userNameField.SendKeys(USERNAME);
                userPasswordField.SendKeys(PASSWORD);
            }
        }
Пример #3
0
 private void InitChromeDriverIfNeccessary()
 {
     if (_chromeDriver == null)
     {
         var service = ChromeDriverService.CreateDefaultService();
         service.HideCommandPromptWindow = true;
         ChromeOptions options = new ChromeOptions();
         options.AddExcludedArgument("enable-automation");
         options.AddAdditionalCapability("useAutomationExtension", false);
         options.AddArgument("--log-level=3");
         _chromeDriver = new ChromeDriver(service, options);
         //_chromeDriver.Manage().Window.Position = new System.Drawing.Point( -1000, -1000 );
         _chromeDriver.Url = @"http://p-bot.ru/";
         _chromeDriver.FindElementByXPath(@"//*[@id=""btnSay""]").Click();
     }
 }
Пример #4
0
        public void NoticeCrawling()
        {
            _driverService = ChromeDriverService.CreateDefaultService();
            _driverService.HideCommandPromptWindow = true;
            _options = new ChromeOptions();
            _options.AddArgument("headless");
            _options.AddArgument("disable-gpu");
            _driver = new ChromeDriver(_driverService, _options);

            _driver.Navigate().GoToUrl("https://ieilms.jbnu.ac.kr/");             // 웹 사이트에 접속합니다.

            _driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);

            IWebElement element;

            try
            {
                element = _driver.FindElementByXPath("//*[@id='id']");
                element.SendKeys(VM.mainWindowIDInformation.LoginID);

                element = _driver.FindElementByXPath("//*[@id='passwd']");
                element.SendKeys(VM.mainWindowIDInformation.LoginPasswd);

                element = _driver.FindElementByXPath("//*[@id='loginform']/table/tbody/tr[1]/td[2]/input");
                element.Click();

                element = _driver.FindElementByXPath("//*[@id='boardAbox']/form/table/tbody/tr[1]/td[2]");
                element.Click();
            }
            catch (Exception)
            {
                MessageBox.Show("ID,PW를 확인해주세요.");
                return;
            }

            element = _driver.FindElementByXPath("//*[@id='nav']/li[11]/a");
            element.Click();
            try
            {
                for (int i = 2; i < _driver.FindElements(By.XPath("//*[@id='treebox']/div/table/tbody/tr")).Count; i++)
                {
                    string BASE_Path  = "//*[@id='treebox']/div/table/tbody/tr[{0}]/td[2]/table/tbody/tr/td[4]/span";
                    string url        = string.Format(BASE_Path, i);
                    string BASE_value = url;
                    element = _driver.FindElementByXPath(BASE_value);
                    element.Click();
                    Thread.Sleep(300);
                    TextUpLoad4();
                }
            }catch (Exception ex)
            {
                return;
            }
            _driver.Close();
        }
Пример #5
0
        static void Main(string[] args)
        {
            ChromeDriver driver = new ChromeDriver();


            driver.Navigate().GoToUrl("https://passport.cnblogs.com/user/signin");
            driver.Manage().Window.Maximize();//窗口最大化,便于脚本执行

            //设置超时等待(隐式等待)时间设置10秒
            driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10000);

            driver.FindElementByXPath("//*[@id=\"input1\"]").SendKeys("username");

            driver.FindElementByXPath("//*[@id=\"input2\"]").SendKeys("password");

            driver.FindElementByXPath("//*[@id=\"signin\"]").Click();
            Thread.Sleep(3000);
            driver.FindElementByXPath("//*[@id=\"captchaBox\"]/div/div[2]/div[1]/div[3]/span[1]").Click();
            Actions actions = new Actions(driver);

            Thread.Sleep(3000);
            driver.GetScreenshot().SaveAsFile("原始验证图.png");
            // /html/body/div[3]/div[2]/div[1]/div/div[1]/div[2]/div[2]
            driver.FindElementByXPath("/html/body/div[3]/div[2]/div[1]/div/div[1]/div[2]/div[2]").Click();
            //actions.DragAndDropToOffset(driver,leftShift,0).Build().Perform();//单击并在指定的元素上按下鼠标按钮,然后移动到指定位置
            Thread.Sleep(3000);
            driver.GetScreenshot().SaveAsFile("阴影验证图.png");

            //E:\LoginTest-master\LoginTest-master\LoginTest\bin\Debug
            Bitmap a = new Bitmap(@"E:\LoginTest-master\LoginTest-master\LoginTest\bin\Debug\原始验证图.png");
            Bitmap b = new Bitmap(@"E:\LoginTest-master\LoginTest-master\LoginTest\bin\Debug\阴影验证图.png");
            int    c = GetArgb(a, b);

            actions.DragAndDropToOffset(driver.FindElementByXPath("/html/body/div[3]/div[2]/div[1]/div/div[1]/div[2]/div[2]"), c - 494, 0).Build().Perform();//移动滑块到阴影处


            List <Rectangle> Compare = ImageComparer.Compare(a, b);

            foreach (Rectangle item in Compare)
            {
                Thread.Sleep(2000);
                actions.DragAndDropToOffset(driver.FindElementByXPath("/html/body/div[3]/div[2]/div[1]/div/div[1]/div[2]/div[2]"), item.X + 13, 0).Build().Perform();   //移动滑块到阴影处
            }

            while (true)
            {
                Thread.Sleep(1000);
                Console.WriteLine(0);
            }
        }
        public static ReadOnlyCollection <Cookie> GetCookies(string userEmail)
        {
            var user          = BaseUsers.GetUser(userEmail);
            var chromeOptions = new ChromeOptions();

            chromeOptions.AddArguments("headless");
            var driver = new ChromeDriver(chromeOptions);

            driver.Navigate().GoToUrl(ConfigurationHelper.MainUrl + SitePages.Login);
            driver.FindElementById("Email").SendKeys(user.Email.Value);
            driver.FindElementByName("Password").SendKeys(user.Password);
            driver.FindElementByXPath("//button[.='Log in']").Click();
            var driverCookies = driver.Manage().Cookies.AllCookies;

            return(driverCookies);
        }
Пример #7
0
        private void Bt_click(object sender, RoutedEventArgs e)
        {
            ChromeDriver driver = new ChromeDriver();

            driver.Navigate().GoToUrl("http://uitestpractice.com/Students/Widgets");

            //enter the path file onto the file-selection input field
            var chooseFile = driver.FindElementById("image_file");

            chooseFile.SendKeys("C:\\Users\\Admin\\Downloads\\HDSD-chuyen-tien-qua-the-tren-ARCIB.pdf");

            //Click upload file button
            var btnUpload = driver.FindElementByXPath(".//input[@value='Upload']");

            btnUpload.Click();
            MessageBox.Show(chooseFile.GetAttribute("id"));
        }
Пример #8
0
        public void TextWithCategorySearchingTest()
        {
            using (var driver = new ChromeDriver())
            {
                driver.Navigate().GoToUrl("http://*****:*****@value='Filter']");
                button.Click();
                driver.GetScreenshot().SaveAsFile(TextWithCategorySearchingScreenshotName, System.Drawing.Imaging.ImageFormat.Png);
            }
        }
Пример #9
0
        private void button2_Click(object sender, EventArgs e)
        {
            _driver.FindElementById("login-tayara-code").SendKeys(textBox1.Text);
            _driver.FindElementById("login-tayara-code").Submit();
            _driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(30);
            if (_driver.FindElementByXPath("//div[text()='Nizar Zaddem']") != null)
            {
                Console.WriteLine("connected");
            }
            var sb = new StringBuilder();

            foreach (var c in _driver.Manage().Cookies.AllCookies)
            {
                sb.Append($"{c.Name}={c.Value};");
            }
            File.WriteAllText("ses", sb.ToString());
        }
Пример #10
0
        public override void Execute(WorkNodeArgment arg)
        {
            // 작업노드 시작시 수행루틴
            arg.cbOnChangeWorkState(arg.prevType, m_type, "");
            ChromeDriver driver = arg.seleMgr.GetDriver();

            Util.Logger logger = arg.logger;

            try
            {
                // 로그인 화면 버튼 찾아서 클릭
                var element = driver.FindElementByCssSelector(".d:nth-child(3) > div > .i");
                element.Click();
                Thread.Sleep(2000);

                // id, pw 입력
                element = driver.FindElementById("emailAddress-input");
                element.SendKeys("*****@*****.**");
                Thread.Sleep(100);

                // 로그인 클릭
                element = driver.FindElementById("password-input");
                element.SendKeys("!8189809goD");
                Thread.Sleep(100);

                // 로그인 클릭
                element = driver.FindElementById("login-button");
                element.Click();
                Thread.Sleep(3000);

                // 메인화면으로 이동
                element = driver.FindElementByXPath("//*[@id=\"__next\"]/div/header/div/div/a[1]");
                element.Click();
                Thread.Sleep(3000);
            }
            catch (Exception e)
            {
                arg.cbOnErrorWorkNode(m_type, "로그인 수행 실패");
                logger.OutputError(e.StackTrace, e.Message);
                return;
            }

            // 다음작업으로 이동
            arg.prevType = m_type;
            m_workManager.GoNextWork(TYPE_WORK.ClearCart, arg);
        }
        public void Test()
        {
            //Print the parent window

            string parentWindow = driver.CurrentWindowHandle;

            Console.WriteLine("Parent window's handle -> " + parentWindow);

            for (int i = 0; i < 3; i++)
            {
                IJavaScriptExecutor jse = (IJavaScriptExecutor)driver;

                //Get element object of new browser window button

                IWebElement newBrowserWindow_Element = driver.FindElementByXPath(newBrowserWindow_Xpath);

                jse.ExecuteScript("arguments[0].click()", newBrowserWindow_Element);
            }

            //Get all windows of both one parent and many childs

            List <String> stringWindow = driver.WindowHandles.ToList();

            foreach (string item in stringWindow)
            {
                //print each and very window in the list of string windows

                Console.WriteLine(item);

                //Switch to child window which is fetched from the focused window

                driver.SwitchTo().Window(item);

                //Navigates to the goodle chrome url

                driver.Navigate().GoToUrl("https://www.google.com/");
            }


            //Must assign to focus another window to continue using the next command

            driver.SwitchTo().Window(stringWindow.ElementAt(3));

            driver.Close();
        }
Пример #12
0
        public static void Main(string[] args)
        {
            //  var options = new ChromeOptions();
            //  options.AddArguments("--disable-gpu");

            var chromeDriver = new ChromeDriver();

            var wait = new WebDriverWait(chromeDriver, new TimeSpan(0, 0, 30));

            chromeDriver.Navigate().GoToUrl("https://login.yahoo.com/config/login?.intl=us&.lang=en-US&.src=finance&.done=https%3A%2F%2Ffinance.yahoo.com%2F");
            //chromeDriver.FindElementByXPath("//*[@id='login - username']");

            var userName = chromeDriver.FindElementById("login-username");

            userName.SendKeys("stephcshea");
            var loginButton = chromeDriver.FindElementById("login-signin");

            loginButton.Click();

            var element = wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.Id("login-passwd")));

            var userPassword = chromeDriver.FindElementById("login-passwd");

            userPassword.SendKeys("Abby7777!");
            var loginButton2 = chromeDriver.FindElementById("login-signin");

            loginButton2.Click();

            chromeDriver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(120);

            chromeDriver.Navigate().GoToUrl("https://finance.yahoo.com/portfolio/p_1/view/v1");

            var popup = wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.Id("__dialog")));

            var closePopup = chromeDriver.FindElementByXPath("//dialog[@id = '__dialog']/section/button");

            closePopup.Click();


            var profile = wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.Id("main")));

            var profileTable = chromeDriver.FindElement(By.XPath("//*[@id=\"main\"]/section/header/div/div[1]/div/div[2]/p[1]")).Text;

            System.Console.WriteLine("profileTable: ", profileTable);
        }
Пример #13
0
        private void buttonLogin_Click(object sender, EventArgs e)
        {
            try
            {
                _driver = new ChromeDriver(_driverService, _options);

                _driver.Navigate().GoToUrl("https://manatoki95.net/");

                _driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);

                var element = _driver.FindElementByXPath("//*[@id='basic_outlogin']/div[1]/button");
                element.Click();
            }
            catch (Exception exc)
            {
                Trace.WriteLine(exc.Message);
            }
        }
        //Passing the complete div to get all the values and choose the specific element depending upon the value passed.
        public string get_xpath_area(ChromeDriver driver)
        {
            int    count = driver.FindElements(By.XPath(pg.choose_area_dropdown)).Count;
            string temp  = "";

            for (int i = 1; i <= count; i++)
            {
                String check = driver.FindElementByXPath(pg.choose_area_dropdown + "[" + i + "]/span[2]").Text;

                if (check.CompareTo(sp.City_area) == 0)
                {
                    temp = pg.choose_area_dropdown + "[" + i + "]/span[2]";
                }
            }


            return(temp);
        }
Пример #15
0
        private void NewSkinChangePass(ChromeDriver ch, ProfileInfo profileInfo, Controllers.KChromeExtension kChromeExtension)
        {
            string passNew = txtPassNew.Text.Trim();

            ch.Navigate().GoToUrl("https://www.facebook.com/settings?tab=security");
            string cquick_token = Regex.Match(ch.PageSource, @"compat_iframe_token"":""(.*?)""").Groups[1].Value;


            ch.Navigate().GoToUrl("https://www.facebook.com/settings?tab=security&section=password&view&cquick=jsc_c_e&cquick_token=" + cquick_token + "&ctarget=https%3A%2F%2Fwww.facebook.com");
            //ch.FindElementByName("password_old").SendKeys(profileInfo.password);
            kChromeExtension.waitForPageElementIsVisible(ch, By.Name("password_old")).SendKeys(profileInfo.password);
            System.Threading.Thread.Sleep(100);
            ch.FindElementByName("password_new").SendKeys(passNew);
            System.Threading.Thread.Sleep(100);
            ch.FindElementByName("password_confirm").SendKeys(passNew);
            System.Threading.Thread.Sleep(100);
            ch.FindElementByXPath("//input[@type='submit']").Click();
        }
Пример #16
0
        public void SearchProduct()
        {
            try
            {
                string product = "70-410";

                Chrome.Navigate().GoToUrl(site);
                Chrome.FindElement(By.Id("ctl00_wpm_HomePage_ctl01_Simplesearch_SearchPhrase")).Clear();
                Chrome.FindElement(By.Id("ctl00_wpm_HomePage_ctl01_Simplesearch_SearchPhrase")).SendKeys(product);
                Chrome.FindElementById("ctl00_wpm_HomePage_ctl01_Simplesearch_SearchButton").Click();
                Chrome.FindElementByXPath("//*[@id=\"ctl00_wpm_SearchPage_ctl05_SearchResultsAjaxPanel\"]/table/tbody/tr");
                Console.WriteLine("ESTO FUNCIONA DEL MAMI QUEVEDO");
            } catch (Exception e)
            {
                Console.WriteLine("EEEEERROOOOOOOR: " + e);
                Assert.Fail();
            }
        }
Пример #17
0
        public YourPokerRoomsPage_VotingProcess FillUpAllFields(string name, string email, string password)
        {
            driver.FindElementByName("inputName").SendKeys(name);
            driver.FindElementByName("inputEmail").SendKeys(email);
            driver.FindElementByName("inputPassword").SendKeys(password);
            IWebElement clickSignUp = driver.FindElementByXPath("//*[text()='Sign up']");

            clickSignUp.Click();
            wait.Until(ExpectedConditions.ElementToBeClickable(By.Id("profile-img")));
            IWebElement clickOnProfileImage = driver.FindElementById("profile-img");

            clickOnProfileImage.Click();
            IWebElement clickOnSignOut = driver.FindElementByCssSelector("a[href*='/authentication/logout/']");

            clickOnSignOut.Click();

            return(new YourPokerRoomsPage_VotingProcess(driver));
        }
        public string get_xpath_maxbath(ChromeDriver driver)
        {
            int    count = driver.FindElements(By.XPath(pg.max_bathroom_dropdown_elem)).Count;
            string temp  = "";

            for (int i = 1; i <= count; i++)
            {
                string check = driver.FindElementByXPath(pg.max_bathroom_dropdown_elem + "[" + i + "]").Text.ToString().Replace(" bathroom", "").Replace("s", "");


                if (check.CompareTo(sp.MaxBathroom.ToString()) == 0)
                {
                    temp = pg.max_bathroom_dropdown_elem + "[" + i + "]";
                }
            }


            return(temp);
        }
        public string get_xpath_propertytype(ChromeDriver driver)
        {
            int    count = driver.FindElements(By.XPath("//*[@id='ptId_ul']/li")).Count;
            string temp  = "";

            for (int i = 1; i <= count; i++)
            {
                string check = driver.FindElementByXPath("//*[@id='ptId_ul']/li[" + i + "]/label").Text;


                if (check.CompareTo(sp.Property_type) == 0)
                {
                    temp = "//*[@id='ptId_ul']/li[" + i + "]/label";
                }
            }


            return(temp);
        }
Пример #20
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            ChromeDriver chromeDriver = new ChromeDriver();

            chromeDriver.Url = "https://tiki.vn/dien-thoai-samsung-galaxy-a80-128gb-8gb-hang-chinh-hang-p14380981.html?src=recently-viewed&spid=14380983&utm_expid=.nQFRzANBRd6g9IFUqkkl8g.0&utm_referrer=https%3A%2F%2Ftiki.vn%2F";
            chromeDriver.Navigate();

            //Set during time to wait displayed loading page
            chromeDriver.Manage().Window.Maximize();
            chromeDriver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(30);

            var element = chromeDriver.FindElementByXPath("/html/body/div[10]/div[2]/div[1]/div[2]/div/div[2]/div[1]/div/div/div[1]/p[3]/span[1]");

            //Get value attribute of css
            MessageBox.Show(element.GetAttribute("class"));

            //Get value css of element
            MessageBox.Show(element.GetCssValue("line-height"));
        }
        static void Main(string[] args)
        {
            var options = new ChromeOptions();

            options.AddArguments("--disable-gpu");
            options.AddArguments("disable-popup-blocking"); //to disable pop-up blocking

            var chromeDriver = new ChromeDriver(options);   //create chrome driver

            //var wait = new chromeDriverWait(chromeDriver, TimeSpan.FromSeconds(20));

            chromeDriver.Navigate().GoToUrl("https://login.yahoo.com/");//navigate to google.com
            Console.WriteLine("Hello I'm in yahoo finance");

            chromeDriver.Manage().Window.Maximize();                                  //maximizes the window
            chromeDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10); //implicitly wait until the next search element is found
            chromeDriver.FindElement(By.Id("login-username")).SendKeys("*****@*****.**");
            chromeDriver.FindElement(By.Id("login-signin")).Click();
            //implicitly wait until the next search element is found
            chromeDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);

            chromeDriver.FindElement(By.Id("login-passwd")).SendKeys("@nuk1978");
            chromeDriver.FindElement(By.Id("login-signin")).Click();
            //implicitly wait until the next search element is found
            chromeDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
            chromeDriver.Url = ("https://finance.yahoo.com/portfolio/p_1/view/v1");
            //chromeDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
            Console.WriteLine("Hello I'm here");
            var closePopup = chromeDriver.FindElementByXPath("//dialog[@id = '__dialog']/section/button");

            closePopup.Click();
            // chromeDriver.FindElementByXPath("//*[@id=\"fin-tradeit\"]/div[2]/div/div/div[2]/button[2]").Click();//click on the pop-up window using X-path to disable it.

            Console.WriteLine("Hello I'm here2");
            var items = chromeDriver.FindElementsByXPath("//*[@id=\"main\"]/section/section[2]/div[2]/table/tbody/tr[*]/td[*]");

            Console.WriteLine("Hello I'm here3");

            foreach (var item in items)
            {
                Console.WriteLine("My watchlist : " + item.Text);
            }
        }
Пример #22
0
        public static void Main(string[] args)
        {
            var options = new ChromeOptions();

            options.AddArguments("--disable-gpu");

            var chromeDriver = new ChromeDriver();

            chromeDriver.Navigate().GoToUrl("https://old.reddit.com/");
            //chromeDriver.FindElementByXPath("//input[@id='login']").Click();
            //chromeDriver.FindElementByXPath("//input[@id='search']").Click();


            chromeDriver.FindElementByXPath("//input*[@id='search']").Click();
            chromeDriver.Keyboard.SendKeys("test");
            chromeDriver.Keyboard.SendKeys(Keys.Enter);

            Console.WriteLine("Hello Reddit!");
        }
Пример #23
0
        public static async Task <IEnumerable <Line> > GetAllLines(string getStops)
        {
            const string allLinesEndpoint = "https://www.stcp.pt/pt/viajar/linhas/";
            const string resultsFilter    = "(//*[@id='viajar_linha'])";

            bool getAllStops = getStops.Equals("stops") ? true : false;

            var co = new ChromeOptions();

            co.AddArgument("headless");
            co.AcceptInsecureCertificates = true;
            co.PageLoadStrategy           = PageLoadStrategy.Normal;

            using (var driver = new ChromeDriver(co))
            {
                try
                {
                    driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
                    driver.Navigate().GoToUrl(allLinesEndpoint);
                    var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));

                    wait.Until(wt => !string.IsNullOrWhiteSpace(wt.FindElement(By.CssSelector("body > div.divGeralContent > div.divContentCenter > div.content-padding > table > tbody > tr > td > div > div.floatLeft > div.panel-linha-sentido > div.title")).Text));

                    var resultString = driver.FindElementByXPath(resultsFilter).GetAttribute("outerHTML");

                    driver.Close();

                    if (string.IsNullOrEmpty(resultString))
                    {
                        throw new HttpRequestException("Error reading page: No results found!");
                    }

                    var result = await ParseAllLines(resultString, getAllStops);

                    return(result);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
Пример #24
0
        private bool CheckIfElementIsShownOnPage(ChromeDriver driver, Identifier type, string elementIdentifier)
        {
            try
            {
                var  wait            = new WebDriverWait(driver, new TimeSpan(0, 0, 5));
                bool elementExisting = wait.Until(condition =>
                {
                    try
                    {
                        IWebElement loadedElement = null;

                        if (type == Identifier.CLASS)
                        {
                            loadedElement = driver.FindElementByClassName(elementIdentifier);
                        }
                        else if (type == Identifier.ID)
                        {
                            loadedElement = driver.FindElementById(elementIdentifier);
                        }
                        else if (type == Identifier.XPATH)
                        {
                            loadedElement = driver.FindElementByXPath(elementIdentifier);
                        }
                        else
                        {
                            return(false);
                        }

                        return(loadedElement.Displayed);
                    }
                    catch (Exception)
                    {
                        return(false);
                    }
                });
                return(elementExisting);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Пример #25
0
        public void CareRequestPageTest()
        {
            var testPhoneNumber = "7733969481";
            var testEmail       = "*****@*****.**";
            var firstNameValue  = "iryna";
            var lastNameValue   = "Lemeha";

            using (var driver = new ChromeDriver())
            {
                driver.Navigate().GoToUrl("http://nitro.duckdns.org/Pets.QA/index.html");

                var navigationMenuPage = new NavigationMenuPage(driver);
                navigationMenuPage.OpenCareRequestPage();

                var careRequestPage = new CareRequestPage(driver);
                careRequestPage.FillOutContactInformation(firstNameValue, lastNameValue, testPhoneNumber, testEmail);

                careRequestPage.RequestCatCare("3+");
                careRequestPage.RequestOtherCare("2");
                careRequestPage.SetVisitsPerDay(2);
                careRequestPage.FillOutComments("Hello World");
                careRequestPage.ClickRequestButton();
                careRequestPage.GetHeaderText();



                Thread.Sleep(1000);

                var closeButton = driver.FindElementByXPath("//button[.='Close']");


                var modal     = driver.FindElement(By.ClassName("modal-body"));
                var modalText = modal.Text;
                Console.WriteLine(modalText);
                modalText.ShouldContain($"Phone #: {testPhoneNumber}");
                modalText.ShouldContain($"Email: {testEmail}");
                modalText.ShouldContain($"First Name: {firstNameValue}");
                modalText.ShouldContain($"Last Name: {lastNameValue}");

                closeButton.Click();
            }
        }
Пример #26
0
        public static void Main(string[] args)
        {
            //var options = new ChromeOptions();
            //options.AddArguments("--disable-gpu");

            var chromeDriver = new ChromeDriver();

            chromeDriver.Navigate().GoToUrl("http://petrowiki.org");

            chromeDriver.FindElementByXPath("//*[@id=\"searchInput\"]").Clear();
            chromeDriver.Keyboard.SendKeys("geophysics");
            chromeDriver.Keyboard.SendKeys(Keys.Enter);

            var titles = chromeDriver.FindElementsByClassName("mw-search-result-heading");

            foreach (var title in titles)
            {
                Console.WriteLine(title.Text);
            }
        }
Пример #27
0
 public void FirstTestMethod()
 {
     try
     {
         driver.Navigate().GoToUrl("https://rozetka.com.ua/");
         Thread.Sleep(2000);
         var searchField = driver.FindElementByXPath("//input[@name='search']");
         searchField.SendKeys("ps4");
         var buttonFiled = driver.FindElementByCssSelector("button.button.button");
         buttonFiled.Click();
         IWebElement[] element    = driver.FindElementsByClassName("g-i-tile").Where(e => e.GetAttribute("class").Contains("g-i-tile-catalog")).ToArray();
         var           price      = element[0].FindElement(By.ClassName("g-price-uah"));
         string        priceValue = price.Text;
         Assert.AreEqual("9 499 грн", priceValue);
     }
     catch
     {
         driver.Quit();
     }
 }
        private static IWebElement GetTokenElement(ChromeDriver driver)
        {
            IWebElement token;

            try
            {
                token = driver.FindElementByXPath("/html/body/div[1]/div/div/div[3]/div/div[2]/div/div[3]/div[1]/div/div/div[2]/div/div/div/div/div[1]/div[1]/div[1]");
            }
            catch (NoSuchElementException)
            {
                //Expected to occur when done so no printing to console...
                token = null;
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                token = null;
            }
            return(token);
        }
Пример #29
0
        public static IWebElement FindElementByXPath(ChromeDriver driver, string xpath, int timeout = 15000)
        {
            IWebElement element = null;
            var         s       = new Stopwatch();

            s.Start();
            while (s.Elapsed < TimeSpan.FromMilliseconds(timeout))
            {
                Thread.Sleep(5);
                try
                {
                    element = driver.FindElementByXPath(xpath);
                    return(element);
                }
                catch (NoSuchElementException)
                {
                }
            }
            s.Stop();
            return(element);
        }
Пример #30
0
        private void Bt_Click(object sender, RoutedEventArgs e)
        {
            ChromeDriver driver = new ChromeDriver();

            // chuyển trang đến website howkteam.com
            driver.Url = "https://www.w3schools.com/html/tryit.asp?filename=tryhtml_youtubeiframe";
            driver.Navigate();

            // bắt ra trình play video của youtube có id là ytplayer
            var youtubePlayer = driver.FindElementById("iframeResult");

            youtubePlayer.Click();
            driver.SwitchTo().Frame(youtubePlayer);
            driver.SwitchTo().Frame(driver.FindElementByXPath("/html/body/iframe"));



            driver.FindElementByClassName("ytp-youtube-button").Click();

            // tìm ra nút youtube và nhấn vào nó để chuyển qua youtube
        }