3

I using gecko browser and i need select a specific listbox or combobox but same page have in more than one listbox and combobox. I try the following method but it applies to all. And there is no id tag, just a name tag.

enter image description here

    GeckoElementCollection ListeBoxKomboBox = Tarayıcı.Document.GetElementsByTagName("option");
    foreach (GeckoHtmlElement Element in ListeBoxKomboBox)
    {
        if (Element.GetAttribute("value") == "1")
        {
            Element.SetAttribute("selected", "selected");
        }
        if (Element.GetAttribute("value") == "2")
        {
            Element.SetAttribute("selected", "selected");
        }
    }

I do not want you to pick the items with the same value in other boxes. Is this like solution available for gecko?

Community
  • 1
  • 1
EgoistDeveloper
  • 775
  • 2
  • 13
  • 37

1 Answers1

2

I notice that there is a label tag ('Turu' or something:)).

So, you can determine which select box is the proper one by:

  1. Select the LI element that has got a first child which content is 'Turu'
  2. Then selecting the 'combobox' inside that LI element

Notice also, that this code is not really right:

GeckoElementCollection ListeBoxKomboBox = Tarayıcı.Document.GetElementsByTagName("option");

You are getting a collection of ALL options in ALL comboboxes on the page. So, the combo box is actually a parent of the option elements (the select element).

Also, option tags are GeckoOptionElements (can be casted safely), so you can do:

var optionElements= selectBox.GetElementsByTagName("option");
            foreach (GeckoOptionElement optionElement in optionElements)
            {
                if (optionElement.Value == "Foo")
                {
                    optionElement.Selected = true;
                }
            }

Lastly - yes, the solution like in your link is possible in Gecko.

Bartosz
  • 4,406
  • 7
  • 41
  • 80