private void button2_Click(object sender, EventArgs e) { try { if (textBox1.Text.Length != 0) { using (IWebDriver Browser = new OperaDriver()) { Browser.Manage().Window.Maximize(); System.Threading.Thread.Sleep(1000); Browser.Navigate().GoToUrl(@"http://ltsu.ru/login/index.php"); Browser.FindElement(By.Id("username")).SendKeys("admin"); Browser.FindElement(By.Id("password")).SendKeys("ULT@015um"); Browser.FindElement(By.Id("loginbtn")).Click(); foreach (Predmet p in listP) { Browser.Navigate().GoToUrl(textBox1.Text); System.Threading.Thread.Sleep(1000); Browser.FindElement(By.CssSelector(".listing-actions.category-listing-actions a:first-child")).Click(); Browser.FindElement(By.Id("id_name")).SendKeys(p.namePredmet); Browser.FindElement(By.Id("id_submitbutton")).Click(); System.Threading.Thread.Sleep(1000); } } } else { MessageBox.Show("Введите URL!"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
static void Main(string[] args) { IWebDriver driver = new OperaDriver(@"D:\OneDrive\Thang\HOCTAP\PUBLIC PROJECTS\SeleniumCSharp"); driver.Navigate().GoToUrl("http://www.demoqa.com/automation-practice-form"); // Locate by ID attribute var firstName = driver.FindElement(By.Id("firstName")); firstName.SendKeys("Thang"); // Locate by Name attribute var genders = driver.FindElements(By.Name("gender")); foreach (var gender in genders) { if (gender.GetAttribute("value") == "Male") { ClickOnButton(driver, gender); } } //// Locate by Class name attribute //var form = driver.FindElement(By.ClassName("practice-form-wrapper")); ////linkText //driver.FindElement(By.LinkText("Home")); ////partialLinkText //driver.FindElement(By.PartialLinkText("Ho")); //var list = driver.FindElements(By.TagName("a")); //driver.FindElement(By.CssSelector("input[id= ‘userName’]")); //driver.FindElement(By.XPath("//input[@id='userName']")); Console.ReadKey(); driver.Quit(); }
/// <summary> /// Using the Web Driver Manager /// </summary> private static void UsingDriverManager(DriverOption driverOption) { IWebDriver webDriver = null; IDriverConfig driverConfig = null; switch (driverOption) { case DriverOption.Chrome: driverConfig = new ChromeConfig(); webDriver = new ChromeDriver(); break; case DriverOption.Edge: driverConfig = new EdgeConfig(); webDriver = new EdgeDriver(); break; case DriverOption.Firefox: driverConfig = new FirefoxConfig(); webDriver = new FirefoxDriver("./"); break; case DriverOption.IE: driverConfig = new InternetExplorerConfig(); webDriver = new InternetExplorerDriver(); break; case DriverOption.Opera: driverConfig = new OperaConfig(); webDriver = new OperaDriver(); break; } new DriverManager().SetUpDriver(driverConfig); webDriver.Navigate().GoToUrl("https://www.google.com"); System.Console.WriteLine($"Title : {webDriver.Title}"); webDriver.Quit(); }
static void Main(string[] args) { IWebDriver driver = new OperaDriver(); driver.Navigate().GoToUrl("https://localhost:44346"); driver.Manage().Window.Maximize(); IWebElement btnsearch = driver.FindElement(By.Id("btnSignLog")); btnsearch.Click(); IWebElement input = driver.FindElement(By.Id("UsernameSignLog")); input.SendKeys("admin"); IWebElement input1 = driver.FindElement(By.Id("PasswordSignLog")); input1.SendKeys("admin"); //"id = "PasswordSignLog //btnAdd IWebElement btnsearch1 = driver.FindElement(By.Id("btnAdd")); btnsearch1.Click(); }
private void button1_Click(object sender, EventArgs e) { try { using (IWebDriver Browser = new OperaDriver()) { //Ожидание // WebDriverWait wait = new WebDriverWait(Browser, TimeSpan.FromSeconds(5)); Browser.Manage().Window.Maximize(); Browser.Navigate().GoToUrl(@"http://ltsu.ru/login/index.php"); Browser.FindElement(By.Id("username")).SendKeys("operator-228"); Browser.FindElement(By.Id("password")).SendKeys("14976"); Browser.FindElement(By.Id("loginbtn")).Click(); Browser.Navigate().GoToUrl(textURL.Text); System.Threading.Thread.Sleep(int.Parse(textTime.Text)); Browser.FindElement(By.CssSelector(".course-listing-actions div:nth-child(3) .dropdown a:first-child")).Click(); System.Threading.Thread.Sleep(int.Parse(textTime.Text)); Browser.FindElement(By.CssSelector(".dropdown-menu.dropdown-menu-right.menu.align-tr-br.show > a:nth-child(6)")).Click(); System.Threading.Thread.Sleep(2000); List <IWebElement> items = Browser.FindElements(By.CssSelector("#course-category-listings #course-listing .listitem .coursename")).ToList(); List <string> new_item = new List <string>(); for (int i = 0; i < items.Count; i++) { new_item.Add(items[i].GetAttribute("href")); } for (int i = 0; i < new_item.Count; i++) { Browser.Navigate().GoToUrl(new_item[i].ToString()); // wait.Until(item => item.FindElement(By.CssSelector(".listing-actions.course-detail-listing-actions > a:nth-child(3)")).Displayed); System.Threading.Thread.Sleep(1000); Browser.FindElement(By.CssSelector(".listing-actions.course-detail-listing-actions > a:nth-child(3)")).Click(); System.Threading.Thread.Sleep(1000); //папап Browser.FindElement(By.CssSelector("#region-main-box .dropdown:first-child a:first-child")).Click(); System.Threading.Thread.Sleep(1000); Browser.FindElement(By.CssSelector(".dropdown-menu.dropdown-menu-right.menu.align-tr-br.show div:nth-child(2)")).Click(); System.Threading.Thread.Sleep(1000); Browser.FindElement(By.CssSelector(".custom-select.urlselect option:nth-child(3)")).Click(); System.Threading.Thread.Sleep(1000); Browser.FindElement(By.Id("id_name")).SendKeys("Синхронизация с глобальной группой"); Browser.FindElement(By.CssSelector(".fcontainer.clearfix input:nth-child(3)")).SendKeys(textGroup.Text); //Browser.FindElement() System.Threading.Thread.Sleep(1000); Browser.FindElement(By.CssSelector(".form-autocomplete-suggestions li:first-child")).Click(); Browser.FindElement(By.Id("mform1")).Submit(); System.Threading.Thread.Sleep(1000); /* Browser.FindElement(By.CssSelector(".pull-right input")).Click(); * System.Threading.Thread.Sleep(2000); * Browser.FindElement(By.CssSelector(".fcontainer.clearfix > #fitem_id_cohortlist > .felement > input")).SendKeys(textGroup.Text.Trim()); * System.Threading.Thread.Sleep(2000); * Browser.FindElement(By.CssSelector(".fcontainer.clearfix > #fitem_id_cohortlist > .felement > ul > li:first-child")).Click(); * //Может быть Здесь еще нужно поставить Sleep * Browser.FindElement(By.CssSelector(".modal-body > form")).Submit(); * System.Threading.Thread.Sleep(int.Parse(textTime.Text));*/ } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void button1_Click(object sender, EventArgs e) { try { if (textURL.Text.Length != 0) { using (IWebDriver Browser = new OperaDriver()) { string idGroup = string.Empty; Browser.Manage().Window.Maximize(); System.Threading.Thread.Sleep(1000); Browser.Navigate().GoToUrl(@"http://ltsu.ru/login/index.php"); Browser.FindElement(By.Id("username")).SendKeys("admin"); Browser.FindElement(By.Id("password")).SendKeys("ULT@015um"); Browser.FindElement(By.Id("loginbtn")).Click(); Browser.Navigate().GoToUrl(textURL.Text); MatchCollection match = Regex.Matches(textURL.Text, @"(\d+)"); foreach (Match m in match) { idGroup = (m.Groups[1].ToString()); } System.Threading.Thread.Sleep(2000); Browser.Navigate().GoToUrl($"http://ltsu.ru/course/edit.php?category={idGroup}&returnto=catmanage"); System.Threading.Thread.Sleep(2000); foreach (Predmet p in listP) { int random = Randoms(); Browser.FindElement(By.Id("id_fullname")).Clear(); Browser.FindElement(By.Id("id_shortname")).Clear(); Browser.FindElement(By.Id("id_fullname")).SendKeys(p.namePredmet); if (p.namePredmet.Length < 100) { Browser.FindElement(By.Id("id_shortname")).SendKeys(p.namePredmet + "_" + random.ToString()); } else { Browser.FindElement(By.Id("id_shortname")).SendKeys(p.namePredmet.Split(' ') + "_" + random.ToString()); } System.Threading.Thread.Sleep(1000); Browser.FindElement(By.Id("id_saveanddisplay")).Click(); System.Threading.Thread.Sleep(1000); Browser.Navigate().Back(); System.Threading.Thread.Sleep(2000); } } } else { MessageBox.Show("Введите URL"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public static void Main(string[] args) { string currentUser = string.Empty; try { new DriverManager().SetUpDriver(new OperaConfig(), "Latest", Architecture.Auto); string OperaProfilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Opera Software\\Opera Stable"); var jsonText = File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "accounts.json")); var jsonAccounts = JsonConvert.DeserializeObject <List <Account> >(jsonText); OperaOptions opt = new OperaOptions(); opt.PageLoadStrategy = PageLoadStrategy.Eager; opt.AddArgument($"user-data-dir={OperaProfilePath}"); opt.AddArguments(new[] { "--incognito" }); opt.AddAdditionalCapability("useAutomationExtension", false); opt.AddExcludedArgument("enable-automation"); OperaDriverService driverService = OperaDriverService.CreateDefaultService(); driverService.HideCommandPromptWindow = true; for (int i = 0; i <= jsonAccounts.Count; i++) { currentUser = jsonAccounts[i].name; KillAllDrivers(); IWebDriver driver = new OperaDriver(driverService, opt); try { driver.Url = "https://giris.hepsiburada.com"; driver.WaitForPageLoad(); IWebElement elMail = driver.IsElementPresent(By.XPath("//input[@id='txtUserName']")); IWebElement elPass = driver.IsElementPresent(By.XPath("//input[@id='txtPassword']")); IWebElement elBtnLogin = driver.IsElementPresent(By.XPath("//button[contains(text(),'Giriş')]")); if (elMail == null && elPass == null && elBtnLogin == null) { throw new Exception("CANNOT_FIND_LOGINPAGE"); } elMail.Click(); elMail?.Clear(); elMail?.SendKeys(jsonAccounts[i].name); WaitSomeSecond(1); elPass?.Clear(); elPass?.SendKeys(jsonAccounts[i].pass); WaitSomeSecond(1); var touchActions = new Actions(driver); touchActions.MoveToElement(elBtnLogin).Perform(); touchActions.SendKeys(Keys.Enter).Perform(); WaitSomeSecond(1); driver.WaitForPageLoad(); WaitSomeSecond(6); if (!CheckIsLoggedorRegistered(driver, true)) { throw new Exception("CANNOT_LOGIN"); } driver.Navigate().GoToUrl("https://hesabim.hepsiburada.com/iletisim-tercihlerim"); driver.WaitForPageLoad(); WaitSomeSecond(5); var mailNotify = driver.RunJsCommand("return document.querySelector('div.x0LYwM_8u4ipmQOzUpbEM:nth-child(2) > div:nth-child(2) > div:nth-child(1) > label:nth-child(1) > input');"); if (mailNotify != null) { var checkState = (bool)driver.RunJsCommand("return arguments[0].checked", new[] { mailNotify }); if (checkState) { driver.RunJsCommand("arguments[0].click()", new[] { mailNotify }); Console.WriteLine($"{jsonAccounts[i].name} başarılı"); WaitSomeSecond(3); } else { Console.WriteLine($"{jsonAccounts[i].name} zaten kapatılmış"); } } else { throw new Exception("CANNOT_FOUND_MAIL_NOTIFY"); } } catch (Exception e) { Console.WriteLine($"Hesap Adı : {jsonAccounts[i].name}"); Console.WriteLine(e); Thread.Sleep(TimeSpan.FromSeconds(new Random().Next(5, 10))); } driver.Quit(); Thread.Sleep(TimeSpan.FromSeconds(new Random().Next(30, 70))); } } catch (Exception e) { Console.WriteLine(e); } }
private void button1_Click(object sender, EventArgs e) { //IWebDriver Browser = new OperaDriver(); try { if ((textGroup.Text.Length != 0) || (textURL.Text.Length != 0)) { using (IWebDriver Browser = new OperaDriver()) { //Ожидание // WebDriverWait wait = new WebDriverWait(Browser, TimeSpan.FromSeconds(5)); Browser.Manage().Window.Maximize(); Browser.Navigate().GoToUrl(@"http://ltsu.ru/login/index.php"); Browser.FindElement(By.Id("username")).SendKeys("admin"); Browser.FindElement(By.Id("password")).SendKeys("ULT@015um"); Browser.FindElement(By.Id("loginbtn")).Click(); Browser.Navigate().GoToUrl(textURL.Text); System.Threading.Thread.Sleep(int.Parse(textTime.Text)); Browser.FindElement(By.CssSelector(".course-listing-actions div:nth-child(3) .dropdown a:first-child")).Click(); System.Threading.Thread.Sleep(int.Parse(textTime.Text)); Browser.FindElement(By.CssSelector(".dropdown-menu.dropdown-menu-right.menu.align-tr-br.show > a:nth-child(6)")).Click(); System.Threading.Thread.Sleep(2000); List <IWebElement> items = Browser.FindElements(By.CssSelector("#course-category-listings #course-listing .listitem .coursename")).ToList(); List <string> new_item = new List <string>(); for (int i = 0; i < items.Count; i++) { new_item.Add(items[i].GetAttribute("href")); } for (int i = 0; i < new_item.Count; i++) { Browser.Navigate().GoToUrl(new_item[i].ToString()); // wait.Until(item => item.FindElement(By.CssSelector(".listing-actions.course-detail-listing-actions > a:nth-child(3)")).Displayed); System.Threading.Thread.Sleep(1000); Browser.FindElement(By.CssSelector(".listing-actions.course-detail-listing-actions > a:nth-child(3)")).Click(); System.Threading.Thread.Sleep(1000); //папап Browser.FindElement(By.CssSelector(".pull-right input")).Click(); System.Threading.Thread.Sleep(2000); Browser.FindElement(By.CssSelector(".fcontainer.clearfix > #fitem_id_cohortlist > .felement > input")).SendKeys(textGroup.Text.Trim()); System.Threading.Thread.Sleep(2000); Browser.FindElement(By.CssSelector(".fcontainer.clearfix > #fitem_id_cohortlist > .felement > ul > li:first-child")).Click(); //Может быть Здесь еще нужно поставить Sleep Browser.FindElement(By.CssSelector(".modal-body > form")).Submit(); System.Threading.Thread.Sleep(int.Parse(textTime.Text)); } } } else { MessageBox.Show("Введите текст"); } } catch (NoSuchElementException element) { MessageBox.Show("Не найден элемент на сайте!!!!" + "\n" + element.Message); } catch (Exception ex) { MessageBox.Show(ex.Message); } // finally { Browser.Dispose(); } }