public void UIDropTest() { // create a new Internet Explorer instance pointing to the ASP.NET Development Server using (IE ie = new IE(Constants.DevWebSite + "drop.aspx")) { // Maximize the IE window ie.ShowWindow(NativeMethods.WindowShowStyle.Maximize); // Fill in the form ie.TextField(Find.ById("ctl00_PageContentPlaceHolder_QuickMessageControl_SenderTextBox")).TypeText(Constants.Sender); ie.SelectList(Find.ById("ctl00_PageContentPlaceHolder_QuickMessageControl_RecipientDropDownList")).Select(Constants.Recipient); ie.TextField(Find.ById("ctl00_PageContentPlaceHolder_QuickMessageControl_MessageTextBox")).TypeText(MESSAGE); WatiN.Core.FileUpload fUp; fUp = ie.FileUpload(Find.ById("ctl00_PageContentPlaceHolder_QuickMessageControl_MultiUpload_Input_0")); fUp.Set(Constants.File0); fUp = ie.FileUpload(Find.ById("ctl00_PageContentPlaceHolder_QuickMessageControl_MultiUpload_Input_1")); fUp.Set(Constants.File1); fUp = ie.FileUpload(Find.ById("ctl00_PageContentPlaceHolder_QuickMessageControl_MultiUpload_Input_2")); fUp.Set(Constants.File2); ie.CheckBox(Find.ById("ctl00_PageContentPlaceHolder_QuickMessageControl_AcceptTermsCheckBox")).Checked = true; //Click send and wait until end of post if (ie.Button(Find.ById("ctl00_PageContentPlaceHolder_QuickMessageControl_SendButton")).Enabled) { ie.Button(Find.ById("ctl00_PageContentPlaceHolder_QuickMessageControl_SendButton")).ClickNoWait(); SimpleTimer t = new SimpleTimer(60 * 60); Span s; do { s = ie.Span(Find.ById("ctl00_PageContentPlaceHolder_QuickMessageControl_FinalReportLabel")); if (s.Exists) { goto EXIT; } System.Threading.Thread.Sleep(1000); } while (!t.Elapsed); throw new WatiN.Core.Exceptions.TimeoutException(string.Format("waiting {0} seconds for element to show up.", 60 * 60)); EXIT: Div d = ie.Div(Find.ById("ctl00_PageContentPlaceHolder_QuickMessageControl_SendFinalPanel")); Assert.AreEqual(true, ((d.Exists) && (d.Links.Length > 0) && d.Links[0].Url.StartsWith(Constants.DevWebSite, StringComparison.InvariantCultureIgnoreCase))); } else { Assert.IsTrue(false, "Send button is disabled because of incorrect data"); } } }
/// <summary> /// This method checks the browser for the specific field that you have specfied /// </summary> /// <param name="fieldType">The type of field that you are looking for (textbox/select/checkbox/button).</param> /// <param name="fieldId">The id of the field that you are looking for.</param> /// <returns>Boolean value indicating whether the field was found or not.</returns> public bool FieldExists(string fieldType, string fieldId) { switch (fieldType.ToLower()) { case "textbox": return(_browser.ElementOfType <TextFieldExtended>(Find.ById(fieldId)) != null); case "select": return(_browser.SelectList(Find.ById(fieldId)) != null); case "checkbox": return(_browser.CheckBox(Find.ById(fieldId)) != null); case "button": return(_browser.Button(Find.ById(fieldId)) != null); default: return(false); } }
public static WatiN.Core.CheckBox GetCheckBox(IE ie, HControl control) { switch (control.Attribute.ToLower()) { case AttributeType.Id: { CheckBox txt = ie.CheckBox(Find.ById(control.Value)); if (txt.Exists) { return(txt); } return(null); } case AttributeType.Name: { CheckBox txt = ie.CheckBox(Find.ByName(control.Value)); if (txt.Exists) { return(txt); } return(null); } case AttributeType.Class: { CheckBox txt = ie.CheckBox(Find.ByClass(control.Value)); if (txt.Exists) { return(txt); } return(null); } case AttributeType.Text: { CheckBox txt = ie.CheckBox(Find.ByText(control.Value)); if (txt.Exists) { return(txt); } return(null); } case AttributeType.Value: { CheckBox txt = ie.CheckBox(Find.ByValue(control.Value)); if (txt.Exists) { return(txt); } return(null); } default: { CheckBox txt = ie.CheckBox(Find.ById(control.Value)); if (txt.Exists) { return(txt); } return(null); } } }
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(); }
public override void Do(IE ie) { if (ie == null) { ie = Wxs.Instance.Ie; } try { switch (type) { case ClickableType.Radio: if (elementAttributeValue.Contains("*")) { elementAttributeValue = elementAttributeValue.Replace("*", String.Empty); ie.RadioButton( Find.By(elementAttributeName, new Regex(elementAttributeValue))).Click(); } else { ie.RadioButton( Find.By(elementAttributeName, elementAttributeValue)).Click(); } Wxs.Instance.Log.Debug( String.Format("Radio {0}[{1}] clicked", elementAttributeName, elementAttributeValue)); break; case ClickableType.Check: if (elementAttributeValue.Contains("*")) { elementAttributeValue = elementAttributeValue.Replace("*", String.Empty); ie.CheckBox(Find.By(elementAttributeName, new Regex(elementAttributeValue))).Click(); } else { ie.CheckBox( Find.By(elementAttributeName, elementAttributeValue)).Click(); } Wxs.Instance.Log.Debug( String.Format("Check Box {0}[{1}] clicked", elementAttributeName, elementAttributeValue)); break; case ClickableType.Button: if (elementAttributeValue.Contains("*")) { elementAttributeValue = elementAttributeValue.Replace("*", String.Empty); ie.Button( Find.By(elementAttributeName, new Regex(elementAttributeValue))).Click(); } else { ie.Button( Find.By(elementAttributeName, elementAttributeValue)).Click(); } Wxs.Instance.Log.Debug( String.Format("Button {0}[{1}] clicked", elementAttributeName, elementAttributeValue)); break; case ClickableType.TableCell: if (elementAttributeValue.Contains("*")) { elementAttributeValue = elementAttributeValue.Replace("*", String.Empty); ie.TableCell( Find.By(elementAttributeName, new Regex(elementAttributeValue))).Click(); } else { ie.TableCell( Find.By(elementAttributeName, elementAttributeValue)).Click(); } Wxs.Instance.Log.Debug( String.Format("Table cell {0}[{1}] clicked", elementAttributeName, elementAttributeValue)); break; case ClickableType.Div: if (elementAttributeValue.Contains("*")) { elementAttributeValue = elementAttributeValue.Replace("*", String.Empty); ie.Div( Find.By(elementAttributeName, new Regex(elementAttributeValue))).Click(); } else { ie.Div( Find.By(elementAttributeName, elementAttributeValue)).Click(); } Wxs.Instance.Log.Debug( String.Format("Div: {0} [{1}] clicked", elementAttributeName, elementAttributeValue)); break; case ClickableType.Image: if (elementAttributeValue.Contains("*")) { elementAttributeValue = elementAttributeValue.Replace("*", String.Empty); ie.Image( Find.By(elementAttributeName, new Regex(elementAttributeValue))).Click(); } else { ie.Image( Find.By(elementAttributeName, elementAttributeValue)).Click(); } Wxs.Instance.Log.Debug( String.Format("Image {0} [{1}] clicked", elementAttributeName, elementAttributeValue)); break; default: Wxs.Instance.Log.Error("Could not execute click: type not set"); // Should I throw break; } } catch (WatiN.Core.Exceptions.ElementNotFoundException e) { Wxs.Instance.Log.Error(String.Format("Element not found error in test {0}", name), e); //throw (e); } }
public static object FindControlInBrowserByID(IE ie, string strID, Enumerators.ControlType ctrl) { if (ctrl == Enumerators.ControlType.Span) { Span sp = ie.Span(Find.ById(strID)); Assert.IsTrue(sp.Exists, "Could not Find: " + strID); return(sp); } else if (ctrl == Enumerators.ControlType.Link) { Link lnk = ie.Link(Find.ById(strID)); Assert.IsTrue(lnk.Exists, "Could not Find: " + strID); return(lnk); } else if (ctrl == Enumerators.ControlType.Frame) { Frame iFrame = ie.Frame(Find.ById(strID)); return(iFrame); } else if (ctrl == Enumerators.ControlType.Image) { Image img = ie.Image(Find.ById(strID)); Assert.IsTrue(img.Exists, "Could not Find: " + strID); return(img); } else if (ctrl == Enumerators.ControlType.TableCell) { TableCell tCell = ie.TableCell(Find.ById(strID)); Assert.IsTrue(tCell.Exists, "Could not Find: " + strID); return(tCell); } else if (ctrl == Enumerators.ControlType.Table) { Table tbl = ie.Table(Find.ById(strID)); Assert.IsTrue(tbl.Exists, "Could not Find: " + strID); return(tbl); } else if (ctrl == Enumerators.ControlType.TableRow) { TableRow row = ie.TableRow(Find.ById(strID)); Assert.IsTrue(row.Exists, "Could not Find: " + strID); return(row); } else if (ctrl == Enumerators.ControlType.CheckBox) { CheckBox chk = ie.CheckBox(Find.ById(strID)); Assert.IsTrue(chk.Exists, "Could not Find: " + strID); return(chk); } else if (ctrl == Enumerators.ControlType.Button) { Button btn = ie.Button(Find.ById(strID)); Assert.IsTrue(btn.Exists, "Could not Find: " + strID); return(btn); } else if (ctrl == Enumerators.ControlType.TextField) { TextField txt = ie.TextField(Find.ById(strID)); Assert.IsTrue(txt.Exists, "Could not Find: " + strID); return(txt); } else if (ctrl == Enumerators.ControlType.SelectList) { SelectList sList = ie.SelectList(Find.ById(strID)); Assert.IsTrue(sList.Exists, "Could not Find: " + strID); return(sList); } else if (ctrl == Enumerators.ControlType.Div) { Div division = ie.Div(Find.ById(strID)); Assert.IsTrue(division.Exists, "Could not Find: " + strID); return(division); } else if (ctrl == Enumerators.ControlType.TableRow) { TableRow tRow = ie.TableRow(Find.ById(strID)); Assert.IsTrue(tRow.Exists, "Could not Find: " + strID); return(tRow); } else if (ctrl == Enumerators.ControlType.FileUpload) { FileUpload fileUpload = ie.FileUpload(Find.ById(strID)); Assert.IsTrue(fileUpload.Exists, "Could not find: " + strID); return(fileUpload); } else { return(null); } }
public static object FindControlInBrowserByCustom(IE ie, string strCustomAttribute, string strToFind, Enumerators.ControlType ctrl) { if (ctrl == Enumerators.ControlType.Span) { Span sp = ie.Span(Find.By(strCustomAttribute, strToFind)); Assert.IsTrue(sp.Exists, "Could not Find: " + strToFind); return(sp); } else if (ctrl == Enumerators.ControlType.Link) { Link lnk = ie.Link(Find.By(strCustomAttribute, strToFind)); Assert.IsTrue(lnk.Exists, "Could not Find: " + strToFind); return(lnk); } else if (ctrl == Enumerators.ControlType.Frame) { Frame frame = ie.Frame(Find.By(strCustomAttribute, strToFind)); Assert.AreEqual(frame.Name, strToFind); return(frame); } else if (ctrl == Enumerators.ControlType.Image) { Image img; if (strCustomAttribute == "src") { img = ie.Image(Find.BySrc(strToFind)); } else { img = ie.Image(Find.By(strCustomAttribute, strToFind)); } Assert.IsTrue(img.Exists, "Could not Find: " + strToFind); return(img); } else if (ctrl == Enumerators.ControlType.TableCell) { TableCell tCell = ie.TableCell(Find.By(strCustomAttribute, strToFind)); Assert.IsTrue(tCell.Exists, "Could not Find: " + strToFind); return(tCell); } else if (ctrl == Enumerators.ControlType.Table) { Table tbl = ie.Table(Find.By(strCustomAttribute, strToFind)); Assert.IsTrue(tbl.Exists, "Could not Find: " + strToFind); return(tbl); } else if (ctrl == Enumerators.ControlType.TableRow) { TableRow row = ie.TableRow(Find.By(strCustomAttribute, strToFind)); Assert.IsTrue(row.Exists, "Could not Find: " + strToFind); return(row); } else if (ctrl == Enumerators.ControlType.CheckBox) { CheckBox chk = ie.CheckBox(Find.By(strCustomAttribute, strToFind)); Assert.IsTrue(chk.Exists, "Could not Find: " + strToFind); return(chk); } else if (ctrl == Enumerators.ControlType.Button) { Button btn = ie.Button(Find.By(strCustomAttribute, strToFind)); Assert.IsTrue(btn.Exists, "Could not Find: " + strToFind); return(btn); } else if (ctrl == Enumerators.ControlType.TextField) { TextField txt = ie.TextField(Find.By(strCustomAttribute, strToFind)); Assert.IsTrue(txt.Exists, "Could not Find: " + strToFind); return(txt); } else if (ctrl == Enumerators.ControlType.SelectList) { SelectList sList = ie.SelectList(Find.By(strCustomAttribute, strToFind)); Assert.IsTrue(sList.Exists, "Could not Find: " + strToFind); return(sList); } else if (ctrl == Enumerators.ControlType.Div) { Div div = ie.Div(Find.By(strCustomAttribute, strToFind)); Assert.IsTrue(div.Exists, "Could not Find: " + strToFind); return(div); } else { return(null); } }
private void clickConsolidatedConsent() { ie.CheckBox(Constants.BlueBirdConstants.CONSOLIDATEDCONSENT_ELEMENT_ID).Click(); }