L
L
libera2015-12-15 14:28:41
C++ / C#
libera, 2015-12-15 14:28:41

Doesn't loop?

int i;
            for (i = 0; i <= 10; i++)
            {
                
                    Random rand_date = new Random();
                    foreach (HtmlElement element1 in webBrowser.Document.All)
                    {
                        if (element1.GetAttribute("name") == "migrationRequest.dayOfBirth")
                        {
                            element1.Children[rand_date.Next(1, element1.Children.Count)].SetAttribute("selected", "true");
                        }
                    }
                    foreach (HtmlElement element2 in webBrowser.Document.All)
                    {
                        if (element2.GetAttribute("name") == "migrationRequest.monthOfBirth")
                        {
                            element2.Children[rand_date.Next(1, element2.Children.Count)].SetAttribute("selected", "true");
                        }
                    }
                    foreach (HtmlElement element3 in webBrowser.Document.All)
                    {
                        if (element3.GetAttribute("name") == "migrationRequest.yearOfBirth")
                        {
                            element3.Children[rand_date.Next(1, element3.Children.Count)].SetAttribute("selected", "true");
                        }
                    
                }

He has to do it 10 times, but he only does it once.
tell me what's wrong.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alec Onim, 2015-12-15
@libera

looked at the site, looked at your questions, but isn't it better to use JS for such purposes?
Actually something like this, I checked it, it works all 11 times: D

public System.Windows.Forms.WebBrowser webBrowser = new System.Windows.Forms.WebBrowser();

public MainWindow()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            for (i = 0; i <= 10; i++)
            {
                webBrowser.Navigate(new Uri("https://account.mojang.com/migrate"));
                webBrowser.Navigated+=DoWork;
            }
        }

        private void DoWork(object sender, WebBrowserNavigatedEventArgs e)
        {
            Random rand_date = new Random();
            foreach (HtmlElement element1 in webBrowser.Document.All)
            {
                if (element1.GetAttribute("name") == "migrationRequest.dayOfBirth")
                {
                    element1.Children[rand_date.Next(1, element1.Children.Count)].SetAttribute("selected", "true");
                }
            }
        }

V
Vladimir Martyanov, 2015-12-15
@vilgeforce

It's not that you're not using a debugger.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question