我正在尝试使用XPath命令选择特定的单选按钮:
driver.FindElement(By.XPath("//td[contains(@input id, 'SearchTypePatientNameDob')]")).Click();
包含我想要的按钮的列表如下:
<tr>
<td>
<input id="RadioButtonSearchTypePatientNameDob" type="radio" value="SearchTypePatientNameDob" name="SearchType">
<span class="Instructions">Patient Name / Patient Date of Birth</span>
</td>
</tr>
我的命令找不到要选择/单击的按钮。任何建议将大有裨益。
最佳答案
您需要找到input
元素,而不是td
元素:
//input[contains(@id, 'SearchTypePatientNameDob')]
请注意,我看不到任何合理的原因,为什么您不使用简单的
By.Id
定位器:driver.FindElement(By.Id("RadioButtonSearchTypePatientNameDob")).Click();
您可能还需要显式wait for the element to be present。
关于c# - 在C#中使用XPath选择单选按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30463170/