示例#1
0
        public void MarkowiczTransformacjaTest()
        {
            browser.Navigate().GoToUrl("http://markowicz.pro");
            //var articleTitle = browser.FindElement(By.XPath("//*[@id='post-261']//*[@class='entry-title']"));
            //var articleTitle = browser.FindElement(By.Id("post-261"));

            var articles = browser.FindElementsByCssSelector(".entry-title > a");

            foreach (var article in articles)
            {
                var href = article.GetAttribute("href");
                if (href == "http://markowicz.pro/o-transformacjach/")
                {
                }
            }

            IWebElement expected = null;
            //var userName = browser.FindElementByClassName("author vcard");

            var results = browser.FindElementsByCssSelector("span > a");

            foreach (var result in results)
            {
                if (result.GetAttribute("href") == "http://markowicz.pro/author/rafal-markowicz/")
                {
                    expected = result;
                    break;
                }
            }



            Assert.NotNull(expected);
        }
 public void ThenIHaveTheSuccessfulResult()
 {
     Assert.IsTrue(_chromeDriver.FindElementsByCssSelector(".alert-success").Count > 0);
     Thread.Sleep(1000);
     _chromeDriver.Close();
     _chromeDriver.Dispose();
 }
示例#3
0
        public IEnumerable <string> FindGroupMembers(string groupTitle)
        {
            _driver.Manage().Window.Maximize();
            _driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(7);
            _driver.Navigate().GoToUrl(_skypeUrl);

            var         groups      = _driver.FindElementsByCssSelector(".rxCustomScroll.rxCustomScrollV.active div[role = button]");
            IWebElement findedGroup = null;

            foreach (var group in groups)
            {
                var title = group.GetAttribute("aria-label");
                if (title.IndexOf(groupTitle) >= 0)
                {
                    findedGroup = group;
                    break;
                }
            }

            findedGroup.Click();

            var membersButton = _driver.FindElementByCssSelector("div[data-text-as-pseudo-element$='участник']");

            membersButton.Click();

            var membersAdditionalButton = _driver.FindElementByCssSelector("div[data-text-as-pseudo-element$='Дополнительно']");

            membersAdditionalButton.Click();

            var membersHtmlElements = _driver.FindElementsByCssSelector("div[role=group] > div[role=button]");
            var members             = membersHtmlElements.Select(m => m.GetAttribute("aria-label").Replace(", ", string.Empty)).ToList();

            _driver.Close();
            return(members);
        }
        public void Publication_UserCanViewPublications()
        {
            // Arrange
            bool expected = true;

            // Act
            bool actual = false;

            try
            {
                var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(100));
                wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementExists(
                               By.CssSelector(
                                   "#root > div > div.MuiPaper-root.MuiTableContainer-root.MuiPaper-elevation1.MuiPaper-rounded > table > tbody > tr")));

                var publicationList = driver.FindElementsByCssSelector(
                    "#root > div > div.MuiPaper-root.MuiTableContainer-root.MuiPaper-elevation1.MuiPaper-rounded > table > tbody > tr");

                if (publicationList.Count > 0)
                {
                    actual = true;
                }
            }
            catch
            {
                actual = false;
            }

            driver.Close();

            // Assert
            Assert.Equal(expected, actual);
        }
示例#5
0
        public void testAlbert()
        {
            driver.Navigate().GoToUrl("https://contactbook.kopan77.repl.co/contacts");
            var    contacts  = driver.FindElementsByCssSelector(".contact-entry");
            string firstName = "";
            string lastName  = "";

            foreach (var contact in contacts)
            {
                string stringifiedContact = contact.Text.ToLower();
                if (stringifiedContact.Contains("albert"))
                {
                    firstName = contact.FindElement(By.CssSelector(".contact-entry .fname td")).Text;
                    lastName  = contact.FindElement(By.CssSelector(".contact-entry .lname td")).Text;
                    if (firstName == "Albert" && lastName == "Einstein")
                    {
                        break;
                    }
                }
            }

            string testName = firstName + lastName;

            Assert.AreEqual("AlbertEinstein", testName);
        }
        public void AmazonEbatTestMethod()
        {
            using (var driver = new ChromeDriver())
            {
                // 1. Maximize the browser
                driver.Manage().Window.Maximize();

                // 2. Go to the "Amazon" homepage
                driver.Navigate().GoToUrl("https://www.amazon.com/");

                // 3. Find the search textbox (by ID) on the homepage
                var searchBox = driver.FindElementById("twotabsearchtextbox");

                // 4. Enter the text (to search for) in the textbox
                searchBox.SendKeys("Iphone 7");


                // 5. Find the search button (by Name) on the homepage
                var searchButton = driver.FindElementById("nav-search-submit-text");

                // 6. Click "Submit" to start the search
                searchButton.Submit();

                // 7. Find the "Id" of the "Div" containing results stats,
                // located just above the results table.
                var sort = driver.FindElementById("sort");

                Actions actions = new Actions(driver);
                actions.MoveToElement(sort).Perform();

                var sortPrice = driver.FindElementByCssSelector("#sort > option:nth-child(3)");

                sortPrice.Click();


                IReadOnlyCollection <IWebElement> searchResults = driver.FindElementsByCssSelector("a > h2");

                IReadOnlyCollection <IWebElement> searchResultsPrice = driver.FindElementsByCssSelector("span.a-color-base.sx-zero-spacing");


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


                var searchBoxeBay = driver.FindElementById("gh-ac");

                searchBoxeBay.SendKeys("Iphone 7");

                var searchButtoneBay = driver.FindElementById("gh-btn");

                searchButtoneBay.Click();

                IReadOnlyCollection <IWebElement> searchResultseBay = driver.FindElementsByCssSelector("a > h3");


                IReadOnlyCollection <IWebElement> searchResultsPriceEBay = driver.FindElementsByCssSelector(".s-item__price");
            }
        }
示例#7
0
        public void TestLinksImages()
        {
            driver.FindElementById("menu-item-11969").Click();
            var links = driver.FindElementsByCssSelector("#works a");

            string[] factions = { "isengard", "factions/elves", "factions/mordor" };
            for (int i = 0; i < factions.Length; i++)
            {
                Assert.AreEqual(links[i].GetAttribute("href"), url + factions[i] + '/');
            }
        }
示例#8
0
        public void ClickingOnLocaleShouldShowDropdown()
        {
            _browser.Navigate().GoToUrl(_basehost);
            var dropdownElement = _browser.FindElementsByCssSelector(".header__controls_dropdown").Last();

            Assert.False(dropdownElement.Displayed);

            _browser.FindElementsByCssSelector(".header__controls_label").Last().Click();

            Assert.True(dropdownElement.Displayed);
        }
示例#9
0
 protected ReadOnlyCollection <IWebElement> GetElementsWithCSSSelector(string cssSelector)
 {
     try
     {
         bool elementsExist = Wait.Until(d => Driver.FindElementsByCssSelector(cssSelector).Any());
         return(Driver.FindElementsByCssSelector(cssSelector));
     }
     catch (Exception ex)
     {
         return(new ReadOnlyCollection <IWebElement>(new List <IWebElement>()));
     }
 }
示例#10
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            ChromeOptions options = new ChromeOptions();

            options.AddArgument("--headless");
            options.AddArgument("--disable-gpu");
            options.AddArgument("--no-sandbox");
            options.AddArgument("--log-level=3");
            using (ChromeDriver chromeDriver = new ChromeDriver())
            {
                chromeDriver.Url = "https://www.realestate.com.au/buy";
                chromeDriver.Navigate();
                var searchInputElement = chromeDriver.FindElementByCssSelector("input.rui-input.rui-location-box.rui-auto-complete-input");
                searchInputElement.SendKeys("Sunnybank, QLD 4109; ");
                var searchButtonElement = chromeDriver.FindElementByCssSelector("button.rui-search-button");
                searchButtonElement.Click();
                var           advertisements = chromeDriver.FindElementsByCssSelector("div.listingInfo.rui-clearfix");
                List <string> addresses      = new List <string>();
                foreach (var advertisement in advertisements)
                {
                    var addressElement = advertisement.FindElement(By.CssSelector("div.vcard"));
                    addresses.Add(addressElement.Text);
                }

                //var mapLinkElement = chromeDriver.FindElementById("mapLink");

                //mapLinkElement.Click();

                Debugger.Break();
            }
        }
示例#11
0
        public List <string> Search()
        {
            ChromeDriverService service = ChromeDriverService.CreateDefaultService();

            service.HideCommandPromptWindow = true;
            var driver = new ChromeDriver(service);

            driver.Manage().Window.Maximize();
            driver.Navigate().GoToUrl("https://www.kinopoisk.ru");
            Thread.Sleep(1000);
            var inp = driver.FindElement(By.ClassName("header-fresh-search-partial-component__field"));

            inp.SendKeys(filmName);
            inp.Submit();
            var film = driver.FindElementByClassName("name").FindElement(By.ClassName("js-serp-metrika"));

            film.Click();
            var    info          = driver.FindElementsByCssSelector(".info tbody tr td a");
            var    name          = driver.FindElementByClassName("moviename-title-wrapper");
            string infoAboutFilm = $"Название фильма - {name.Text}\n" +
                                   $"Год выпуска {info[0].Text}\n" +
                                   $"Страна производства {info[1].Text}\n" +
                                   $"Режисёр {info[2].Text}";
            List <string> data = new List <string>();

            data.Add(infoAboutFilm);
            var    img = driver.FindElementByCssSelector("a.popupBigImage img");
            string src = img.GetAttribute("src");

            data.Add(src);
            return(data);
        }
示例#12
0
        private IWebElement ElementSelector(ChromeDriver cDriver, string secici, int selectorType)
        {
            if (cDriver == null || string.IsNullOrWhiteSpace(secici))
            {
                throw new ArgumentException("invalid argüment");
            }

            ReadOnlyCollection <IWebElement> bulunan = null;

            switch (selectorType)
            {
            case 1:
                bulunan = cDriver.FindElementsByXPath(secici);
                break;

            case 2:
                bulunan = cDriver.FindElementsByCssSelector(secici);
                break;

            case 3:
                bulunan = cDriver.FindElementsById(secici);
                break;
            }
            return(bulunan != null && bulunan.Count > 0 ? bulunan[0] : null);
        }
        public ReadOnlyCollection <IWebElement> FindElementsByCssSelector(string cssSelector, int second = 3)
        {
            try
            {
                var wait = new WebDriverWait(ChromeDriver, TimeSpan.FromSeconds(second));
                wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.CssSelector(cssSelector)));
                var result = ChromeDriver.FindElementsByCssSelector(cssSelector);

                if (result != null)
                {
                    return(result);
                }
            }
            catch (Exception ex)
            {
                try
                {
                    IJavaScriptExecutor js = (IJavaScriptExecutor)ChromeDriver;
                    var jsresult           =
                        js.ExecuteScript(
                            $"return document.querySelectorAll('{cssSelector}')");
                    return(jsresult as ReadOnlyCollection <IWebElement>);
                }
                catch (Exception)
                {
                }
            }
            return(null);
        }
示例#14
0
        /// <summary>
        /// 簽退
        /// </summary>
        private static void SignOut()
        {
            using (var driver = new ChromeDriver("."))
            {
                //開啟網頁
                driver.Navigate().GoToUrl(_url);
                Thread.Sleep(2000);

                //點擊執行
                var submitButton = driver.FindElementsByCssSelector("button.checkout");
                Thread.Sleep(2000);
                submitButton.FirstOrDefault().Click();
                Thread.Sleep(2000);

                //如果有重複點選簽退
                try
                {
                    var confirm_win = driver.SwitchTo().Alert();
                    confirm_win.Accept();
                }
                catch (System.Exception ex)
                {
                }

                Thread.Sleep(2000);

                Verify(driver);

                driver.Navigate().GoToUrl(_url);
                driver.Quit();
            }
        }
示例#15
0
文件: Parser.cs 项目: badyi/VkParser_
        private List <string> get_Image_Links(ChromeDriver chr, string id)
        {
            char[]        ch = { '"', ')' };
            List <string> listOfImageLinks = (from item in chr.FindElementsByCssSelector("#wpt-" + id + " > div.page_post_sized_thumbs.clear_fix > a") where item.Displayed select item.GetCssValue("background-image").Remove(0, 5).Trim(ch)).ToList();

            return(listOfImageLinks);
        }
示例#16
0
        // lấy link ảnh
        void crawlImage(ChromeDriver chrome, string url, int codeComicDetail)
        {
            chrome.Url = (url);
            chrome.Navigate();

            var nodeList = chrome.FindElementsByCssSelector("select[name='jump'] > option").ToList();


            var linkImage = chrome.FindElementByCssSelector("body > table > tbody > tr:nth-child(5) > td > table > tbody > tr:nth-child(1) > td:nth-child(1) > a > img").GetAttribute("src");
            //http://web4.cartoonmad.com/c8n3o733a62/1416/033/001.jpg
            string imageOrigin = linkImage.ToString().Substring(0, linkImage.Length - 7);

            for (int i = 1; i < nodeList.Count; i++)
            {
                ComicDetailImgae image = new ComicDetailImgae();

                if (i < 10)
                {
                    image.link = imageOrigin + "00" + i + ".jpg";
                }
                else if (i < 99 && i > 9)
                {
                    image.link = imageOrigin + "0" + i + ".jpg";
                }

                image.codeComicDetail = codeComicDetail;

                db.ComicDetailImgaes.Add(image);
                db.SaveChanges();
            }
        }
示例#17
0
        public void CreatingNewIssueSavesCorrectly()
        {
            var data = new
            {
                Title       = "Issue",
                Description = "Fix all the bugs",
                Status      = IssueStatus.Done
            };

            using (var driver = new ChromeDriver(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)))
            {
                driver.Navigate().GoToUrl(@"https://*****:*****@"https://localhost:5000/Issue/Create", driver.Url);
                var titleInput = driver.FindElementById("Title");
                titleInput.SendKeys(data.Title);
                var descriptionInput = driver.FindElementById("Description");
                descriptionInput.SendKeys(data.Description);
                var statusSelect  = driver.FindElementById("Status");
                var selectElement = new SelectElement(statusSelect);
                selectElement.SelectByValue($"{(int)data.Status}");
                var createButton = driver.FindElementByCssSelector("input.btn.btn-default");
                Assert.Equal("Create", createButton.GetAttribute("value"));
                createButton.Click();
                /* PAGE CHANGE */
                Assert.Equal(@"https://localhost:5000/Issue", driver.Url);
                var table = driver.FindElementByTagName("tbody");
                var rows  = table.FindElements(By.CssSelector("tr"));
                foreach (var row in rows)
                {
                    var columns = row.FindElements(By.TagName("td"));
                    var col1    = columns.First();
                    var col2    = columns.Skip(1).First();
                    var col3    = columns.Skip(2).First();

                    var edit         = col3.FindElement(By.CssSelector("a[href^='/Issue/Edit/']"));
                    var editHref     = edit.GetAttribute("href");
                    var editValue    = edit.Text;
                    var editIdString = editHref.Substring(editHref.LastIndexOf("/") + 1);
                    var editId       = int.Parse(editIdString);
                    if (existingIds.Contains(editId))
                    {
                        continue;
                    }

                    Assert.Equal(data.Title, col1.Text);
                    Assert.Equal(data.Description, col2.Text);
                    return;
                }
                throw new NotFoundException("Did not find new Issue in table");
            }
        }
        private string ReadNextPageUrl(ChromeDriver driver)
        {
            var nextPageSelector = "div.page-nav.td-pb-padding-side > a";
            var nextPage         = driver.FindElementsByCssSelector(nextPageSelector);
            var nextUrl          = nextPage?.Last().GetAttribute("href");

            return(nextUrl);
        }
示例#19
0
 public void SearchForBartosz_YieldsBarthoszPage()
 {
     using var driver = new ChromeDriver();
     driver.Navigate().GoToUrl("https://bing.com");
     driver.FindElementById("sb_form_q").SendKeys("bartosz software testing\r\n");
     driver.FindElementsByCssSelector("#b_results a")[0].Click();
     Assert.AreEqual("Home - Bartosz", driver.Title);
 }
示例#20
0
        public MainFrm()
        {
            InitializeComponent();

            CheckForIllegalCrossThreadCalls = false;
            var service = ChromeDriverService.CreateDefaultService();

            service.HideCommandPromptWindow = true;
            driver = new ChromeDriver(service);
            driver.Navigate().GoToUrl("https://www.n11.com/c*k-satanlar");
            var urunAdlari    = driver.FindElementsByCssSelector("h3.productName");;
            var urunFiyatlari = driver.FindElementsByCssSelector("div.proDetail ins");

            for (int i = 0; i < urunAdlari.Count; i++)
            {
                txtUrunler.AppendText(urunAdlari[i].Text + " ( " + urunFiyatlari[i].Text + " )" + Environment.NewLine + Environment.NewLine);
            }
        }
        private IEnumerable <string> ReadArticleUrls(ChromeDriver driver)
        {
            var hrefsSelector = "div.td_module_5.td_module_wrap.td-animation-stack > div.td-item-details.td-category-small > h3.entry-title.td-module-title > a";
            var hrefs         = driver.FindElementsByCssSelector(hrefsSelector);

            var urls = hrefs.Select(m => m.GetAttribute("href"));

            return(urls);
        }
示例#22
0
        public void GivenIWantToAccessMyAccount()
        {
            Thread.Sleep(3000);
            var Atags = _driver.FindElementsByCssSelector("a[href *= 'https://accounts.google.com/ServiceLogin?']");

            if (Atags.Count() != 0)
            {
                Atags.Where(c => c.Text.Contains("SIGN")).First().Click();
            }
        }
示例#23
0
        public UGSearch GetSearchResult(BasicSong track, UGType type)
        {
            // TODO multi-page support
            string fullUrl = $"{baseURL}{track.searchString}&type={(int)type}";

            this.browser.Navigate().GoToUrl(fullUrl);
            var mainList = browser.FindElementsByCssSelector("article > div > div");

            return(new UGSearch(mainList));
        }
示例#24
0
 private IEnumerable <IWebElement> FindElementsCss(ChromeDriver driver, string css)
 {
     try
     {
         return(driver.FindElementsByCssSelector(css));
     }
     catch (NoSuchElementException)
     {
         return(null);
     }
 }
        internal void ClickLogInBtn()
        {
            var loginBtn           = driver.FindElementsByCssSelector(".btn.btn-lg.btn-primary");
            var referenceClassName = "btn btn-lg btn-primary btn-action btn-disabled";

            var btnLogIn = loginBtn
                           .Where(btn => btn.GetAttribute("class") != "btn btn-lg btn-primary btn-action btn-disabled")
                           .FirstOrDefault();

            btnLogIn.Click();
        }
示例#26
0
        //lấy link tập
        void crawlTrap(ChromeDriver chrome, string url, int codeComic)
        {
            chrome.Url = (url);
            chrome.Navigate();

            var nodeList = chrome.FindElementsByCssSelector("#info > table > tbody > tr > td > a").ToList();

            var nameComic = chrome.FindElementsByCssSelector("body > table > tbody > tr:nth-child(1) > td:nth-child(2) > table > tbody > tr:nth-child(3) > td:nth-child(2) > a:nth-child(6)").FirstOrDefault().Text + "漫畫";

            //漫畫 : truyện tranh
            foreach (var item in nodeList)
            {
                ComicDetail comic = new ComicDetail();
                comic.link      = item.GetAttribute("href");
                comic.name      = nameComic + "-" + item.Text;
                comic.codeComic = codeComic;

                db.ComicDetails.Add(comic);
                db.SaveChanges();
            }
        }
示例#27
0
        public int IndexOfUserInTable(string userename, ChromeDriver crome)
        {
            var users = crome.FindElementsByCssSelector(userNameInTable);

            for (int i = 0; i < users.Count; i++)
            {
                if (users[i].Text == userename)
                {
                    return(i);
                }
            }
            return(-1);
        }
示例#28
0
        public void CreatingNewIssueSavesCorrectly()
        {
            var data = new
            {
                Title       = "Issue",
                Description = "Fix all the bugs",
                Status      = IssueStatus.Done,
            };

            using (var driver = new ChromeDriver(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)))
            {
                driver.Navigate().GoToUrl(@"https://*****:*****@".*/Issue/Create", driver.Url);
                var titleInput = driver.FindElementById("Title");
                titleInput.SendKeys(data.Title);
                var descriptionInput = driver.FindElementById("Description");
                descriptionInput.SendKeys(data.Description);
                var statusSelect  = driver.FindElementById("Status");
                var selectElement = new SelectElement(statusSelect);
                selectElement.SelectByValue($"{(int)IssueStatus.Done}");
                var createInput = driver.FindElementByCssSelector(".btn");
                createInput.Click();
                Assert.Equal(@"https://localhost:5000/Issue", driver.Url);
                var table = driver.FindElementByCssSelector("tbody");
                var rows  = table.FindElements(By.CssSelector("td"));
                foreach (var row in rows)
                {
                    var columns      = row.FindElements(By.TagName("td"));
                    var col1         = columns.First();
                    var col2         = columns.Skip(1).First();
                    var col3         = columns.Skip(2).First();
                    var edit         = col3.FindElement(By.CssSelector("a[href^='/Issue/Edit/']"));
                    var editIdString = edit.GetAttribute("href").Replace("/Issue/Edit/", "");
                    var editId       = int.Parse(editIdString);
                    if (!existingIds.Contains(editId))
                    {
                        continue;
                    }
                    Assert.Equal(data.Title, col1.Text);
                    Assert.Equal(data.Description, col2.Text);
                    return;
                }
                throw new NotFoundException("did not find new issue in table");
            }
        }
示例#29
0
        private void mesajGonder()
        {
            string numara = listViewNumaralar.Items[count].SubItems[0].Text;
            string api    = "https://api.whatsapp.com/send?phone=" + numara + "&text=" + mesaj;

            driver.Url = api;
            var actionButton = ElementSelector(driver, "action-button", BY_ID);

            actionButton.Click();
            lblDurum.Text = numara + " mesaj gönderiliyor ...";
            Thread.Sleep(500);
            if (driver.FindElementsByCssSelector("[data-animate-modal-body]").Count == 0)
            {
                while (true)
                {
                    Thread.Sleep(1500);
                    var spanDataIconSend = ElementSelector(driver, "span[data-icon=send]", BY_CSS_SELECTOR);
                    if (spanDataIconSend != null)
                    {
                        if (chkDosyaGonder.Checked)
                        {
                            lblDurum.Text = "Dosya Gönderiliyor ...";
                            Thread.Sleep(2000);
                            DosyayiEkranaSurukle();
                            Thread.Sleep(1000);
                            resmiGonder();
                            Thread.Sleep(int.Parse(txtBeklemeSuresi.Text));
                            lblDurum.Text = "Dosya Gönderildi";
                        }

                        else
                        {
                            Thread.Sleep(3000);
                            driver.ExecuteScript("document.querySelector('span[data-icon=send]').closest('button').click()");
                        }

                        break;
                    }
                }
            }

            listViewNumaralar.Items[count].SubItems[1].Text = "Gönderildi";
            progressBar1.Value = count + 1;
            int ss = count + 1;

            this.Text = "WhatsappWeb Mesaj Gönder | ixlarge.com [" + listViewNumaralar.Items.Count + "] / [" + ss + "]";
            listViewNumaralar.Items[count++].SubItems[1].ForeColor = Color.Green;

            Atesle();
        }
示例#30
0
        private bool BookDay(ChromeDriver driver, string date)
        {
            var dayElement = driver
                             .FindElementsByCssSelector($":not(.flatpickr-disabled)[aria-label='{date}']")
                             .FirstOrDefault();

            if (dayElement != null)
            {
                dayElement.Click();
                driver.WaitFor(By.Id("form_next")).Click();

                return(true);
            }

            return(false);
        }