gpt4 book ai didi

javascript - 我如何找到 radio 的输入元素并检查它?总是 "Unable to find element "

转载 作者:行者123 更新时间:2023-11-28 05:36:59 24 4
gpt4 key购买 nike

我正在用c#学习selenium,我试图获取 radio 的输入元素,但总是“无法找到元素”

 <div>
<span id="ctl00_ContentPlaceHolder1_ucObservationSearch1_rblAdvancedSearch" class="radioListOptions">
<input id="ctl00_ContentPlaceHolder1_ucObservationSearch1_rblAdvancedSearch_0" type="radio" checked="checked" value="My" name="ctl00$ContentPlaceHolder1$ucObservationSearch1$rblAdvancedSearch">
<label for="ctl00_ContentPlaceHolder1_ucObservationSearch1_rblAdvancedSearch_0">My</label>
<br>
<input id="ctl00_ContentPlaceHolder1_ucObservationSearch1_rblAdvancedSearch_1" type="radio" onclick="javascript:setTimeout('__doPostBack(\'ctl00$ContentPlaceHolder1$ucObservationSearch1$rblAdvancedSearch$1\',\'\')', 0)" value="Workgroup" name="ctl00$ContentPlaceHolder1$ucObservationSearch1$rblAdvancedSearch">
<label for="ctl00_ContentPlaceHolder1_ucObservationSearch1_rblAdvancedSearch_1">Workgroup</label>
<br>
<input id="ctl00_ContentPlaceHolder1_ucObservationSearch1_rblAdvancedSearch_2" type="radio" onclick="javascript:setTimeout('__doPostBack(\'ctl00$ContentPlaceHolder1$ucObservationSearch1$rblAdvancedSearch$2\',\'\')', 0)" value="Division" name="ctl00$ContentPlaceHolder1$ucObservationSearch1$rblAdvancedSearch">
<label for="ctl00_ContentPlaceHolder1_ucObservationSearch1_rblAdvancedSearch_2">Division</label>
</span>
</div>

我已经尝试过

 ReadOnlyCollection<IWebElement> links1 = driver.FindElements(By.XPath("//input[contains(text(),'Workgroup')]"));
ReadOnlyCollection<IWebElement> links1 = driver.FindElements(By.XPath("//input[contains(@value,'Workgroup')]"));
IWebElement check = driver.FindElement(By.Id("ctl00_ContentPlaceHolder1_ucObservationSearch1_rblAdvancedSearch_1"));

我也尝试过使用 javascript 在控制台中

document.getElementById("ctl00_ContentPlaceHolder1_ucObservationSearch1_rblAdvancedSearch_1").checked=true

返回“类型错误:document.getElementById(...) 为空”我没有更多解决方案,我需要一些帮助,谢谢

我发现这个html中多了一个html,也许这就是为什么总是失败的原因,有人知道如何处理它吗?

最佳答案

试试这个..

 document.addEventListener("DOMContentLoaded", function (event) {
document.getElementById("ctl00_ContentPlaceHolder1_ucObservationSearch1_rblAdvancedSearch_1").checked = true;

});

关于javascript - 我如何找到 radio 的输入元素并检查它?总是 "Unable to find element ",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39287096/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com