How to click the checkbox using Selenium WebDriver and C#

前端 未结 4 507
挽巷
挽巷 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:33

    As per the HTML you have shared to invoke click() on the desired checkbox you can use either of the following solutions:

    • CssSelector:

      driver.FindElement(By.CssSelector("label[for=Url_Transaction_Out]")).Click();
      
    • XPath:

      driver.FindElement(By.XPath("//label[@for='Url_Transaction_Out']")).Click();
      

提交回复
热议问题