Как выбрать список (li) на C# webbrowser

Из кода сайта

td class="tdfield_padding">
                <div class="select_menu" id="id_language_top_main"><ul><li class="option_list"><div tabindex="0" class="edit_select wd_select option_selected" id="settings_generalLanguage_select"><div class="sLeft wd_select_l"></div><div class="sBody text wd_select_m" id="id_language" rel="0">English</div>
                <div class="sRight wd_select_r"></div></div><ul class="ul_obj" id="id_languag_li" style="height: 250px;" o_margin_top="2px"><div class="language_scroll">
                <li id="settings_generalLanguageLi1_select" rel="0"><a onclick="show('settings_generalLanguageSave_button');show('settings_generalLanguageCancel_button')" href="#">English</a></li>
                <li id="settings_generalLanguageLi2_select" rel="1"><a onclick="show('settings_generalLanguageSave_button');show('settings_generalLanguageCancel_button')" href="#">Français</a></li>
                <li id="settings_generalLanguageLi3_select" rel="2"><a onclick="show('settings_generalLanguageSave_button');show('settings_generalLanguageCancel_button')" href="#">Italiano</a></li>
                <li id="settings_generalLanguageLi4_select" rel="3"><a onclick="show('settings_generalLanguageSave_button');show('settings_generalLanguageCancel_button')" href="#">Deutsch</a></li>
                <li id="settings_generalLanguageLi5_select" rel="4"><a onclick="show('settings_generalLanguageSave_button');show('settings_generalLanguageCancel_button')" href="#">Español</a></li>
                <li id="settings_generalLanguageLi6_select" rel="5"><a onclick="show('settings_generalLanguageSave_button');show('settings_generalLanguageCancel_button')" href="#">简体中文</a></li>
                <li id="settings_generalLanguageLi7_select" rel="6"><a onclick="show('settings_generalLanguageSave_button');show('settings_generalLanguageCancel_button')" href="#">繁體中文</a></li>
                <li id="settings_generalLanguageLi8_select" rel="7"><a onclick="show('settings_generalLanguageSave_button');show('settings_generalLanguageCancel_button')" href="#">한국어</a></li>
                <li id="settings_generalLanguageLi9_select" rel="8"><a onclick="show('settings_generalLanguageSave_button');show('settings_generalLanguageCancel_button')" href="#">日本語</a></li>
                <li id="settings_generalLanguageLi10_select" rel="9"><a onclick="show('settings_generalLanguageSave_button');show('settings_generalLanguageCancel_button')" href="#">Русский</a></li>
                <li id="settings_generalLanguageLi11_select" rel="10"><a onclick="show('settings_generalLanguageSave_button');show('settings_generalLanguageCancel_button')" href="#">Português</a></li>
                <li id="settings_generalLanguageLi12_select" rel="11"><a onclick="show('settings_generalLanguageSave_button');show('settings_generalLanguageCancel_button')" href="#">Čeština</a></li>
                <li id="settings_generalLanguageLi13_select" rel="12"><a onclick="show('settings_generalLanguageSave_button');show('settings_generalLanguageCancel_button')" href="#">Nederlands</a></li>
                <li id="settings_generalLanguageLi14_select" rel="13"><a onclick="show('settings_generalLanguageSave_button');show('settings_generalLanguageCancel_button')" href="#">Magyar</a></li>
                <li id="settings_generalLanguageLi15_select" rel="14"><a onclick="show('settings_generalLanguageSave_button');show('settings_generalLanguageCancel_button')" href="#">Norsk</a></li>
                <li id="settings_generalLanguageLi16_select" rel="15"><a onclick="show('settings_generalLanguageSave_button');show('settings_generalLanguageCancel_button')" href="#">Polski</a></li>
                <li id="settings_generalLanguageLi17_select" rel="16"><a onclick="show('settings_generalLanguageSave_button');show('settings_generalLanguageCancel_button')" href="#">Svenska</a></li>
                <li id="settings_generalLanguageLi18_select" rel="17"><a onclick="show('settings_generalLanguageSave_button');show('settings_generalLanguageCancel_button')" href="#">Türkçe</a></li></div></ul></li></ul></div>
        </td>

Я хочу выбрать один из них. Это пример кода, который я использую для открытия списка.

webBrowser1.Document.GetElementById("settings_generalLanguage_select").InvokeMember("click"); // It's only open the list
webBrowser1.Document.GetElementById("settings_generalLanguageLi2_select").InvokeMember("click"); //And this code is nothing happen...

Кто-нибудь может мне помочь? Спасибо!

1 ответ

  1. IE не вызывает событие onclick при программном вызове click.
    Используйте HtmlElement.RaiseEvent для запуска обработчика событий.

    Для li нет выбранного состояния. Если вы хотите переместить фокус клавиатуры, используйте HtmlElement.Фокусировать.