0

I have google around a bit trying to finds some way you can click check boxes by entering a value, similar what you can use to select values in Drop Down List. But havent found a way yet.

I have two check boxes with Yes and No

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>

I'm also using PageObjects,

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

This is the Method I have.

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

    }

Now if im trying this

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

I get an error that it does not find the element

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

Any ideas tips?

1 Answer 1

2

This is the code snippet is in java. You need to pass value either Yes or No it will select respective radio button as the same value used for <input> tag's attribute value

public static void SelectOptions(String value)
{
   driver.findElement(By.xpath("//input[@value='"+value+"']")).click();
 }
Sign up to request clarification or add additional context in comments.

2 Comments

It seems like this should work, getting this error though. Additional information: no such element: Unable to locate element: {"method":"xpath","selector":"//input[@value='NO']"}
I believe xpath is case sensitive, so "NO" will not match, you need to use "No"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.