如何使用Selenium和C#通过值选择元素

问题描述 投票:0回答:2

我有无序列表,当我单击该元素时,它将在此处显示结果是html页面

<div class="dataTables_length col s12" id="dataTables-1_length"><label>Show</label><div class="select-wrapper"><span class="caret">▼</span><input type="text" class="select-dropdown" readonly="true" data-activates="select-options-49a1af1e-da84-b5fc-3c3f-ce38dc701d6a" value="10" wtx-context="444F3577-1027-491E-8B1A-08A1D49E2E7E"><ul id="select-options-49a1af1e-da84-b5fc-3c3f-ce38dc701d6a" class="dropdown-content select-dropdown" style="width: 382px; position: absolute; top: 0px; left: 0px; opacity: 1; display: none;"><li class="active"><span>10</span></li><li class=""><span>25</span></li><li class=""><span>50</span></li><li class=""><span>100</span></li></ul><select name="dataTables-1_length" aria-controls="dataTables-1" class="initialized" wtx-context="3DE7F091-A80A-4AB0-8CB0-0B8D71C12B52"><option value="10">10</option><option value="25">25</option><option value="50">50</option><option value="100">100</option></select></div></div>

hre是我已经使用硒使用c#尝试的方法

   driver.FindElementsByXPath("//ul[@class='dropdown-content select-dropdown']")[0].Click();
            driver.FindElementsByXPath("//span[contains(text(),'100')]")[0].Click();

但是上面的代码仍然失败。然后我尝试使用下面的代码第二

var select = driver.FindElementsByXPath("//input[@class='select-dropdown']")[0];
        select.SendKeys("100");
        select.Click();

但不会点击。

我确定我的编码有问题,希望您能帮助我解决问题,谢谢

c# selenium webdriverwait
2个回答
0
投票

0
投票
display: none;
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.