Struggling to check this checkbox using XPath, but every attempt fails as it accidentally clicks on the link in the legend (Lorem ipsum)
https://i.sstatic.net/v3Wmz.png
HTML code:
https://i.sstatic.net/dyaL0.png
<div class="input-outer checkbox">
<div class="section-head sec-head2">
<!---->
<div class="pull-left">Tick this box</div>
<!----><!---->
<p aria-label="required" class="requiredAsteric">*</p>
</div>
<div class="input-validation">
<div class="input-icon-outer">
<!---->
<!---->
<!---->
<!---->
<input class="filled-in ng-untouched ng-pristine ng-invalid" type="checkbox" aria-label="Acceptera villkor" aria-required="true" aria-describedby="err_icon_prefix2_1" id="icon_prefix2_1"><!---->
<label class="leadform-checkbox" tabindex="0" for="icon_prefix2_1">
<div>
<p>Lorem ipsum dolor sit amet, consectetur <a href="https://www.google.com" target="_blank">adipiscing elit</a> adipiscing elit , sed do <a href="https://www.stackexchange.com" target="_blank">eiusmod tempor </a> incididunt ut labore et dolore magna aliqua.</p>
</div>
</label>
<!---->
</div>
</div>
</div>
All attempts with these XPaths have been unsuccessful.
//label[@class='leadform-checkbox']/div";
//input[@aria-label='Tick this box']";
(//div[@class='input-icon-outer'])[3]";
Seems like the checkbox doesn't use the standard HTML functionality, rather a custom CSS-class that resembles a checkbox. Clicking on the div sends the click to the text content instead of the checkbox, leading to the accidental link click.
Is there a fix for this? How do I direct the click to the square?
Edit: Other fields in the "dialog" are accessible with these XPaths:
String xpText = "//input[@aria-label='text']";
String xpNumber = "//input[@aria-label='number']";
All elements are within the same iframe
. Multiple switches between the main content
and various iframes
were done prior.
The heading 2.2
is visible at the top of the screenshot from the HTML source above, indicating correct frame/content selection. Also, links within the text related to this checkbox were accessible.
Included the complete dialog below for easier reference: