单击值 Selenium 的复选框

Click Checkbox by Value Selenium

我 google 有点试图找到一些方法,您可以通过输入一个值来单击复选框,类似于您可以使用下拉列表中的 select 值。 但是还没找到方法

我有两个带有是和否的复选框

div class="radio">
 <label>
   <input type="radio" name="LongTermContract" value="Yes" autocomplete="off" checked="">Yes
</label>
<label>
<input type="radio" name="LongTermContract" value="No" autocomplete="off">No                                </label>                          
</div>

我也在使用 PageObjects,

[FindsBy(How = How.Name, Using = "LongTermContract")]
public IWebElement radioBtnLongTermContract { get; set; }

这是我的方法。

    public static void SelectOptions(this IWebElement element, string value)
    {
        PropertiesCollection.driver.FindElement(By.XPath("//input[@value='" + value + "']")).Click();

    }

现在如果我尝试这个

public void SelectValue(){
  Reporting("NO"); 
    }

我得到一个错误,它没有找到元素

Additional information: no such element: Unable to locate element: {"method":"xpath","selector":"//input[@value='NO']"}

有什么建议吗?

这是 java 中的代码片段。您需要传递值 YesNo 它将 select 相应的单选按钮与用于 <input> 的值相同标签的属性 value

public static void SelectOptions(String value)
{
   driver.findElement(By.xpath("//input[@value='"+value+"']")).click();
 }