简体   繁体   中英

No way to click on a checkbox using selenium with Java

Here is my HTML element

<div _ngcontent-rju-c99="" class="mb-5 custom-control custom-checkbox">
       <input _ngcontent-rju-c99="" required="" type="checkbox" id="tosAccept" name="tosAccept" 
       angularticslabel="AcceptCgu" angularticsvalue="tosAccepted ? 'accepted' : 'notAccepted'" 
       class="custom-control-input ng-untouched ng-pristine ng-invalid"> ==$0
       <label _ngcontent-rju-c99="" for="tosAccept" class="custom-control-label">Acepto las 
           <a href="some link" target="_blank">condiciones generales de uso</a>
      </label>
</div>

I want to click on the input, which is a checkbox that enable a button, the problem is that i just can't, tried all selectors possible (id, name, css, by xpath, by name by id...) nothing works, the fun fact is that input doesn't end, ( no ) which may cause this problem. but its possible with angular i guess.

Of course i have my timers set ( wait.until(ExpectedConditions.visibilityOfElementLocated )

Any solution please? i'm stuck on this since days

resolved with

WebElement checkbox = driver.findElement(By.id("tosAccept"));
            ((JavascriptExecutor)driver).executeScript("var elem=arguments[0]; setTimeout(function() {elem.click();}, 100)", checkbox);

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