Hi there,

Im working a web browser automation project. There is an ajax controlled dropdown list in a web site.

It was like this;

<option value="test1">test1</option>
<option value="test2">test2</option>
<option value="test3">test3</option>
<option value="test4">test4</option>
<option value="test5">test5</option>

When i was selected test2 ajax is working and its giving another div. (I need this div)

I use this codes;

webbrowser1.Document.GetElementsByTagName("select")[0].Document.GetElementsByTagName("option")[1].SetAttribute("selected", "selected");

Its only changing attribute and for this reason it doesnt working ajax.

How can i select option 1?

Thanks.

I would try to set the SelectedIndex value on the select element, as in...

HtmlElement theList = webBrowser1.Document.GetElementsByTagName("select")[0];
if (theList != null)
{
   theList.SetAttribute("SelectedIndex", "0");
}

Remembering that the options in the select element are zero-based, the first option has an index of zero.

--
Les.

Well this is C# forums, Post your question in ASP.Net forum.....

(I think this is more of a C# question, where the OP is trying to view a webpage, and cause it to post back, rather than an ASP.Net question where he is trying to run a website.)

If the suggestion above doesn't work, you might need to post the form to force a response.

Should not call .document twice which will take you back to body tag of the HTML.

Here is a piece of code which works on my app

'VB.net Syntax but you will know what to do
WebBrowser1.Document.GetElementsByTagName("select").GetElementsByName("gender").Item(0).GetElementsByTagName("option").Item(1).SetAttribute("selected", "true")

Zero based index
item 0 = female
item 1 = male

Set attrib as selected true

Use This code:

        Dim a = WebBrowser1.Document.GetElementsByTagName("option")
        a(0).SetAttribute("selected", "selected") ' > for test1



    for test2:
   use a(1)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.