【问题标题】:Webbrowser dropdown selected已选择网络浏览器下拉菜单
【发布时间】:2018-07-08 05:32:54
【问题描述】:

我无法选择。 我想在下拉列表中选择所需值的数据。

   <div role="combobox" id="rw_71_input" aria-owns="rw_71_listbox" class="rw-dropdown-list rw-widget">
        <div class="rw-widget-input rw-widget-picker rw-widget-container">
            <div class="rw-input rw-dropdown-list-input">Live</div>
            <span class="rw-select">
                <button role="presentational"   class="rw-btn rw-btn-select"><span aria-hidden="true" class="rw-i rw-i-caret-down"></span></button>
            </span></div>
        <div class="rw-popup-container rw-popup-transition-exited">
            <div class="rw-popup-transition">
                <div class="rw-popup"> 
                    <ul id="rw_71_listbox" class="rw-list" role="listbox">
                        <li role="option" aria-selected="true" >Super</li>
                        <li role="option" aria-selected="false" >Live</li>
                        <li role="option" aria-selected="false" >Education</li>
                        <li role="option" aria-selected="false" >Mannas</li>
                    </ul>
                </div>
            </div>
        </div>
    </div>

C#

 webBrowser1.Document.GetElementById("rw_71_listbox").Children[3].SetAttribute("selected", "selected");

【问题讨论】:

    标签: c# web browser


    【解决方案1】:

    那是因为您正在使用“selected”和“selected”设置属性。虽然属性的名称是 aria-selected 并且值是 true 或 false。未选中。

    【讨论】:

    • 我需要紧急帮助来完成这个项目。
    【解决方案2】:

    试试这个:

    HtmlDocument theDoc = webBrowser1.Document; 
    var dropdown = theDoc.GetElementById("rw_71_listbox");
    var dropdownItems = (HtmlElementCollection)dropdown.Children;
    foreach (HtmlElement option in dropdownItems)
    {            
        var value = option.GetAttribute("aria-selected").ToString();
        if (value.Equals("true".ToString()))
        {
            option.SetAttribute("aria-selected", "false");
        }
        if (option.OuterHtml.Contains("Mannas"))
        {
            option.SetAttribute("aria-selected", "true");
            break;
        }
    }
    

    【讨论】:

    • 不是:( :(
    • 第一个设置属性 aria-selected=true 使其为 false & second children[3].outerhtml 将 aria-selected=false 设置为 True。
    • 不是。 var dropdown = theDoc.GetElementById("rw_71_listbox");空对象。
    猜你喜欢
    • 2012-02-20
    • 1970-01-01
    • 2019-01-24
    • 1970-01-01
    • 2021-08-27
    • 1970-01-01
    • 2017-05-10
    • 2014-04-10
    • 1970-01-01
    相关资源
    最近更新 更多