Start New Discussion within our Software Development Community

Here is my code;

// Allows writing to web forms
        void SetText(string attribute, string attName, string value)
        {
            comboBox1.Items.Clear();  

            // Get a collection of all the tags with name "input";
            HtmlElementCollection tagsCollection = webBrowser1.Document.GetElementsByTagName("input");

            foreach (HtmlElement currentTag in tagsCollection)
            {
                //  Displays all the tags in a combobox
                comboBox1.Items.Add(currentTag.GetAttribute(attribute).ToString() + Environment.NewLine);
            }

            // displays required tag
            comboBox1.SelectedIndex = 8; 

            Thread.Sleep(100);

            foreach (HtmlElement currentTag in tagsCollection)
            {
                // If the attribute of the current tag has the name attName
                if (currentTag.GetAttribute(attribute).Equals(attName))

                    // Then set its attribute "value".
                    currentTag.SetAttribute("value", value);       
            }
          
        }

and it's invoked by;

SetText("name", "user_name", "admin");

SetText("name", comboBox1.Text, "telus");

The problem I am having is that I can't pass the text of comboBox1 as the attname but I have to do this as the tag name is different every time I refresh the page.

Can someone show me where I am going wrong please

Marked as solved.

I needed to remove "+ Environment.NewLine" from line 12.

It was adding an extra char to the attname I wanted which was making it useless.

This question has already been answered. Start a new discussion instead.