Home c# Selecting ComboBox elements on the site software

Selecting ComboBox elements on the site software

Author

Date

Category

There is a site, in it 2 combs, you need to make a focus on the 1st combocess and choose an item in it, then put the focus on the 2nd combs and select an item in it.
Here is the code

HTMLWINDOW Frames = WebBrowser1.document.Window.frames [0];
    frames = webbrowser1.document.window.frames [0];
    var elements1 = frames.document.getelementsbytagname ("select");
    Elements1 [0] .focus ();
    SendKeys.send ("{down}");
    Elements1 [1] .focus ();

As you can see, elements inside the Combobox, I choose the imitation of the keypad down on the keyboard. As a result, it turns out that the choice is happening in the second combocess, it seems that it does not have time to put focus, as the down key is pressed.
Please tell me how can this be fixed? Or maybe there is a more intelligent way to choose the elements of a combocess, non-youer imitation of keypad keypad. Thanks in advance!


Answer 1, Authority 100%

I use such a design, it works stably, you can of course add checks if necessary: ​​

# region selection of an item in the drop-down list
/// & LT; Summary & GT;
/// Selecting an item in the drop-down list
/// & LT; / Summary & GT;
/// & lt; param name = "avalue" & gt; the text of the item you want to select in the drop-down & lt; / param & gt;
/// & LT; Returns & gt; If it is impossible to select False & LT; / Returns & GT;
Public Bool SelectItemFromListBox (String Avalue)
{
  HTMLELEMENTCOLLECTION A_TAG = FCURRENTWEBBROWSER.Document.Window.Frames [0] .Document.getelementsBytagname ("SELECT");
  Foreach (HTMLELEMENT HE IN A_TAG)
  {
    if (He.getAttribute ("Name"). Equals ("List Name"))
    {
      he.SetAttribute ( "value", aValue);
      RETURN TRUE;
    }
  }
  RETURN FALSE;
}
#Endregion.
Waiting #region fully loaded web page Webbrowser
/// & LT; Summary & GT;
/// Waiting fully loaded web page Webbrowse
/// & LT; / Summary & GT;
/// & lt; param name = "aCurWebBrowser" & gt; A link to a Web page WebBrowser completion of loading in which to wait & lt; / param & gt;
public static void FullLoadWebPage (WebBrowser aCurWebBrowser)
{
  while (aCurWebBrowser.ReadyState! = WebBrowserReadyState.Complete)
  {
    Application.DoEvents ();
  }
}
#Endregion.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions