我有这个HTML
<div class="Radio">
<label>
<input class id="checkbox" name="category" type="radio" value="1">
<strong> TONY STARK </strong>
</label>
<label>
<input class id="checkbox" name="category" type="radio" value="2">
<strong> IRON MAN </strong>
</label>
<label>
<input class id="checkbox" name="category" type="radio" value="3">
<strong> ROBERT DOWNEY </strong>
</label>
我需要根据选择单选按钮TONY STARK
,IRON MAN
,ROBERT DOWNEY
作为用户并将其作为柔性参数
我尝试过此方法,但任何其他简单方法肯定会对我有所帮助!
driver.FindElement(By.Id("checkbox"));
for(WebElement radiobutton: radiobuttons)
{
if(radiobutton.getAttribute("value").equals("TONY STARK"))
radiobutton.click();
}
您应该尝试使用Xpath
来获取单个单选按钮,并避免如下所示的循环:-
string Xpath = ".//input[following-sibling::strong[contains(.,'TONY STARK')]]";
或者
string Xpath = ".//label[contains(.,'TONY STARK')]/input";
使用以下任意一项Xpath
来查找单选按钮:
var radio = driver.FindElement(By.Xpath(Xpath));
radio.Click();
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句