コード例 #1
0
ファイル: TDB.cs プロジェクト: FirasDhb/LeBOTcoin-OpenSource
 private void TDB_Shown(object sender, EventArgs e)
 {
     browser.GoTo("https://www.leboncoin.fr/");
     if (browser.Div(Find.ByClass("clearfix")).Exists)
     {
         metroLabel2.Text = "Connecté";
     }
     else
     {
         metroLabel2.Text = "En cours de connexion...";
         browser.Button(Find.ByClass("button-white button-secondary popin-open trackable custom-small-hidden")).Click();
         browser.ElementOfType <TextFieldExtended>(Find.ByName("st_username")).Value = "*****@*****.**";
         browser.TextField(Find.ByName("st_passwd")).Value = "1999mbmb";
         browser.Button(Find.ByValue("Se connecter")).Click();
         browser.WaitForComplete();
         if (browser.Div(Find.ByClass("create")).Exists)
         {
             metroLabel2.Text = "Connecté";
         }
         else
         {
             metroLabel2.Text = "Impossible de se connecter";
         }
     }
 }
コード例 #2
0
 private void InitializeForm(string uri)
 {
     using (var browser = new IE(uri))
     {
         var page = browser.Page <MyPage>();
         page.PasswordField.TypeText(Password);
         try
         {
             StringBuilder js = new StringBuilder();
             js.Append(@"var myTextField = document.getElementById('i0116');");
             js.Append(@"myTextField.setAttribute('value', '" + UserName + "');");
             browser.RunScript(js.ToString());
             var field = browser.ElementOfType <TextFieldExtended>("i0116");
             field.TypeText(UserName);
         }
         catch (Exception ex)
         {
             Console.Write(ex.Message + ex.StackTrace);
         }
         page.LoginButton.Click();
         browser.WaitForComplete();
         browser.Button(Find.ById("idBtn_Accept")).Click();
         var    len   = browser.Url.Length - 43;
         string query = browser.Url.Substring(43, len);
         if (query.Length == 50)
         {
             if (!string.IsNullOrEmpty(query))
             {
                 Dictionary <string, string> parameters = ParseQueryString(query, new[] { '&', '?' });
                 if (parameters.ContainsKey("code"))
                 {
                     _code = parameters["code"];
                 }
                 else
                 {
                     _error = Uri.UnescapeDataString(parameters["error_description"]);
                 }
             }
         }
     }
 }
コード例 #3
0
        /// <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);
            }
        }
コード例 #4
0
        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();
        }
コード例 #5
0
 private void fillEmailAddress(string email)
 {
     ie.ElementOfType <TextFieldExtended>(Constants.BlueBirdConstants.EMAILADDRESS_ELEMENT_ID).Value        = email;
     ie.ElementOfType <TextFieldExtended>(Constants.BlueBirdConstants.EMAILADDRESSCONFIRM_ELEMENT_ID).Value = email;
 }