How to click the checkbox using Selenium WebDriver and C#

前端 未结 4 509
挽巷
挽巷 2021-01-24 15:01

What I\'m trying to do is click on (or off) any of the checkboxes on my page. As you can see from the HTML, each checkbox element would appear to have a unique identifier but w

4条回答
  •  别那么骄傲
    2021-01-24 15:47

    To get input with type checkbox just use css selector below.

    Element:

    
    

    Css Selector:

    input[data-yesno-name='Url_Transaction_Out']
    

    Code:

    driver.FindElement(By.CssSelector("input[data-yesno-name='Url_Transaction_Out']")).Click();
    

    To check and select:

    IWebElement checkbox = driver.FindElement(By.CssSelector("input[data-yesno-name='Url_Transaction_Out']"));
    if(!checkbox.IsSelected())
    {
        checkbox.Click();
    }
    

提交回复
热议问题