0

I have been trying various methods to check a check box inside a

<div>
<table id="Table1" class="Foresttable" style="width: 100%;" cellpadding="3" cellspacing="0" 
border="0">
<tbody>
<tr>
<td style="width: 25%;" align="left">
<input id="ChkDeclaration" type="checkbox" name="ctl00$ContentPlaceHolder1$ChkDeclaration"> 
<label for="ChkDeclaration">Yes I agree</label>
</td>
</tr>
</tbody>
</table>
</div>

but its failing.

Trial#1

Dim Actions1 As Selenium.Actions
Actions1.MoveToElement(d.FindElementById("ChkDeclaration")).Click.Perform

It says Object or block variable not set

Trial#2

dim ChkDeclaration0 as selenium.webelement
set ChkDeclaration0=driver.FindElementByID("ChkDeclaration")
ChkDeclaration0.Click

says not clickable at this point, some times WORKS

Trial#3

I tried sendkeys(Keys.Return) also does not work

Pls give some clue how to do this.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Jacob
  • 7
  • 3
  • 2
    The element might not be loaded immediately so you could try doing a `While` loop checking if the element exist before you click it e.g. `Do While driver.FindElementByID("ChkDeclaration") Is Nothing: DoEvents: Loop` and once it escape the loop, it means the element should be loaded and you can then click it. – Raymond Wu Dec 14 '21 at 09:11
  • @Raymond Wu I tried it, It escapes loop but still shows same error. Seems like issue is not related to control not being ready. – Jacob Dec 14 '21 at 11:37

1 Answers1

0

To click() on the you can use either of the following Locator Strategies:

  • Using FindElementByCss:

    d.FindElementByCss("label[for='ChkDeclaration']").click
    
  • Using FindElementByXPath:

    d.FindElementByXPath("//label[@for='ChkDeclaration']").click
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • I tried both above it gives error, when i debug it passes thru successfully.Even i put a delay loop but no difference. Thanks for editing. – Jacob Dec 14 '21 at 11:35