public void LocatingThingsByNonId() { using (var browser = new IE("http://localhost:62727/Pages/ApplyForCreditCard.aspx")) { Div errorContainer = browser.Div(Find.ByClass("error")); SelectList title = browser.SelectList(Find.ByName("Title")); Label ageLabel = browser.Label(Find.ByFor("Age")); TextField applicantAge = browser.TextField(Find.ByLabelText("Age In Years")); TextField applicantAge2 = browser.TextField(Find.By("id", "Age")); // var something = browser.Div(Find.By("someattribute","somevalue")); // Assert.That(something, Is.Not.Null); // Link helpHyperlink = browser.Link(Find.ById("HelpLink")); // Button applyButton = browser.Button(Find.ById("ApplyNow")); // Para nameParagraph = browser.Para(Find.ById("Name")); } }
public static void SelectCheckBoxByName(IE ieInstance, string selectedValue) { CheckBoxCollection cbCollection = ieInstance.CheckBoxes; foreach (CheckBox cb in cbCollection) { if (selectedValue != ieInstance.Label(Find.ByFor(cb.Id)).Text) { continue; } cb.Checked = true; break; } }
public void Leboncoin(BackgroundWorker worker, int z) { if (!log.Text.Contains("Chargement...")) { worker.ReportProgress(0, "Chargement..."); } browser.GoTo("https://www.leboncoin.fr/"); browser.WaitForComplete(); worker.ReportProgress(1); if (browser.Div(Find.ByClass("clearfix")).Exists) { if (!log.Text.Contains("- Connecté")) { worker.ReportProgress(0, "- Connecté"); } } else { worker.ReportProgress(0, "- En cours de connexion..."); browser.Button(Find.ByClass("button-flat button-secondary popin-open trackable custom-small-hidden")).Click(); browser.ElementOfType <TextFieldExtended>(Find.ByName("st_username")).Value = mail; browser.TextField(Find.ByName("st_passwd")).Value = pwd; try { browser.Button(Find.ByValue("Se connecter")).Click(); browser.WaitForComplete(); if (browser.Div(Find.ByClass("create")).Exists) { if (!log.Text.Contains("Connecté")) { worker.ReportProgress(0, "- Connecté"); } } else if (browser.ContainsText("Votre identifiant ou mot de passe est incorrect") || browser.ContainsText("Aucun compte ne correspond à cette adresse e-mail")) { worker.ReportProgress(0, " "); worker.ReportProgress(0, "-- Votre identifiant ou mot de passe est incorrect --"); Kill("connection"); } }catch { worker.ReportProgress(0, "- Erreur lors de la connection."); Kill("connection"); } } if (error != "connection") { worker.ReportProgress(1); browser.GoTo("https://compteperso.leboncoin.fr/account/index.html?ca=12_s"); // Suppression de l'annonce if (browser.Link(Find.ByText(titrelbc)).Exists) { browser.Link(Find.ByText(titrelbc)).Click(); worker.ReportProgress(0, " "); worker.ReportProgress(0, "- Suppression de \"" + titrelbc + "\" en cours..."); browser.Link(Find.ByTitle("Supprimer l'annonce")).Click(); worker.ReportProgress(1); browser.WaitForComplete(); browser.Button(Find.ByName("continue")).Click(); if (browser.ContainsText("L'annonce ci-dessous ne peut pas être supprimée, soit parce qu'elle a déjà été supprimée soit parce qu'elle est en cours de suppression ou de validation") || browser.Text.Contains("Cette annonce est désactivée")) { worker.ReportProgress(0, "- L'annonce a déjà été supprimée!"); } else { browser.Button(Find.ByValue("Valider")).Click(); if (browser.ContainsText("Votre demande de suppression a bien été prise en compte")) { worker.ReportProgress(0, "- L'annonce a été supprimée"); } else { worker.ReportProgress(0, "- Erreur lors de la suppression de l'annonce"); } } worker.ReportProgress(1); } // Mise en ligne de l'annonce browser.GoTo("https://compteperso.leboncoin.fr/account/index.html?ca=12_s"); worker.ReportProgress(0, " "); worker.ReportProgress(0, "- Mise en ligne de \"" + titrelbc + "\"..."); browser.WaitForComplete(); browser.Link(Find.ByText("Déposez une annonce")).Click(); worker.ReportProgress(1); browser.WaitForComplete(); Invoke(new Action(() => { browser.RunScript("$('#category option').filter(function(i, e) { return $(e).text() == '" + catégorie + "'}).prop('selected', 'selected').trigger('change');"); browser.TextField(Find.ById("subject")).Value = titrelbc; browser.TextField(Find.ById("body")).Value = textelbc; browser.ElementOfType <TextFieldExtended>(Find.ById("price")).Value = prixlbc.ToString(); browser.TextField(Find.ByName("zipcode")).Value = zip; browser.TextField(Find.ByName("city")).Value = ville; if (browser.ElementOfType <TextFieldExtended>(Find.ById("phone")).Value == "") { browser.ElementOfType <TextFieldExtended>(Find.ById("phone")).Value = phone; } if (checké == true) { browser.Label("phone_hidden").Click(); } for (int i = 0; i < souscategory.Length; i++) { if (!string.IsNullOrEmpty(souscategory[i])) { try { browser.RunScript("$('#" + souscategoryname[i] + " option').filter(function(i, e) { return $(e).text() == \"" + souscategory[i] + "\"}).prop('selected', 'selected').trigger('change');"); } catch { } if (catégorie == "Voitures" && souscategoryname[i] == "brand") { browser.RunScript("$('#brand option[value=\"" + souscategory[i] + "\"]').prop('selected', true).trigger('change');"); browser.SelectList(Find.ById("model")).WaitUntil("disabled", false.ToString()); browser.RunScript("$('#model option[value=\"" + model + "\"]').prop('selected', true).trigger('change');"); } } } if (browser.ElementOfType <TextFieldExtended>(Find.ById("mileage")).Parent.Parent.Parent.Parent.ClassName == "field") { browser.ElementOfType <TextFieldExtended>(Find.ById("mileage")).Value = mileage; } if (browser.ElementOfType <TextFieldExtended>(Find.ById("cubic_capacity")).Parent.Parent.Parent.Parent.ClassName == "field") { browser.ElementOfType <TextFieldExtended>(Find.ById("cubic_capacity")).Value = cc; } if (browser.ElementOfType <TextFieldExtended>(Find.ById("square")).Parent.Parent.Parent.Parent.ClassName == "field") { browser.ElementOfType <TextFieldExtended>(Find.ById("square")).Value = surface; } if (browser.ElementOfType <TextFieldExtended>(Find.ById("rooms")).Parent.Parent.ClassName == "field") { browser.ElementOfType <TextFieldExtended>(Find.ById("rooms")).Value = piece; } })); worker.ReportProgress(1); if (photo1 != "") { if (File.Exists(photo1)) { browser.FileUpload(Find.ById("image0")).Set(photo1); Invoke(new Action(() => { FocusToPreviousWindow(); })); worker.ReportProgress(0, "Téléchargement de l'image 1..."); browser.Div("uploadPhoto-0").WaitUntil <Element>(element => element.GetAttributeValue("data-state").Equals("uploaded")); } else { worker.ReportProgress(0, "Image 1 non trouvée!"); } worker.ReportProgress(1); } if (photo2 != "") { if (File.Exists(photo2)) { browser.FileUpload(Find.ById("image1")).Set(photo2); Invoke(new Action(() => { FocusToPreviousWindow(); })); worker.ReportProgress(0, "Téléchargement de l'image 2..."); browser.Div("uploadPhoto-1").WaitUntil <Element>(element => element.GetAttributeValue("data-state").Equals("uploaded")); } else { worker.ReportProgress(0, "Image 2 non trouvée!"); } worker.ReportProgress(1); } if (photo3 != "") { if (File.Exists(photo3)) { browser.FileUpload(Find.ById("image2")).Set(photo3); Invoke(new Action(() => { FocusToPreviousWindow(); })); worker.ReportProgress(0, "Téléchargement de l'image 3..."); browser.Div("uploadPhoto-2").WaitUntil <Element>(element => element.GetAttributeValue("data-state").Equals("uploaded")); } else { worker.ReportProgress(0, "Image 3 non trouvée!"); } worker.ReportProgress(1); } browser.CheckBox(Find.ById("phone_hidden")).Click(); //Valider if (browser.Button(Find.ById("newadSubmit")).Exists) { browser.Button(Find.ById("newadSubmit")).Click(); } browser.CheckBox(Find.ById("accept_rule")).Click(); if (browser.Button(Find.ById("lbc_submit")).Exists) { browser.Button(Find.ById("lbc_submit")).Click(); } if (browser.ContainsText("Nous avons bien reçu votre annonce. Nous vous remercions pour votre confiance.")) { worker.ReportProgress(0, "- Annonce mise en ligne!"); } else { worker.ReportProgress(0, "- Problème lors de la mise en ligne"); } worker.ReportProgress(1); // FIN if (rang != 0) { if (z == 1) { Click1(); } else if (z == 2) { Click2(); } worker.CancelAsync(); } else { worker.ReportProgress(100); worker.ReportProgress(0, " "); worker.ReportProgress(0, "-- MISE EN LIGNE TERMINÉE --"); Invoke(new Action(() => { browser.ForceClose(); browser.Dispose(); notifyIcon1.BalloonTipTitle = "Mise en ligne terminée!"; notifyIcon1.BalloonTipText = "LeBOTcoin a bien renouvelé vos annonces."; notifyIcon1.ShowBalloonTip(3500); })); } } worker.Dispose(); }