简体   繁体   中英

C# Selenium web driver can't tick a check box

Have an issue here. My scenario need to tick a check box to be completed and the selenium web driver can't do that as the check box as an element has two location Identifiers in selenium IDE (Xpath and Id).

在此处输入图片说明

When defining the element by one only the code stops at the click action and can't tick the check box, the code is

public void Select_requirement_type_Checkbox_click()
    {
        var Checkbox = _webDriver.FindElementByXPath("//nav/ul/li[3]/tree-renderer/div/rm-checkbox/div/label");
        _webDriver.ExecuteScript("arguments[0].click();", Checkbox);
    } 

I've not used selenium much, but I always tried to make it act as a user clicking their way through a form/page...

So instead of trying to call one of the click event handlers attached to the checkbox, I just called the click() method of the element - and let the browser handle the event.

driver.FindElement(By.CssSelector(sel)).Click();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM