Hi guys okay so I am a relative (read: complete) newbie to Selenium / Java / HTML so apologies if I am asking the obvious. What I need is to be able to
- Click on Specific Checkbox 1 and
- If Specific Checkbox 2 is checked, to uncheck it
Here is the Website HTML:
Specific Checkbox 1
<div class="checkbox"> <label id="agree_to_terms_label" for="agree_to_terms_join" class="visible"> <input id="agree_to_terms_join" name="agree_to_terms" type="checkbox" data-required="true" data-required-message="You need to agree to the *** Account Holder agreement" data-change="" class="parsley-validated"> <span class="left-block"></span> I have read, understand and agree to the <a href="/terms-and-conditions/" target="_blank">*** Account Holder Agreement</a> and acknowledge <a href="/privacy-policy" target="_blank">*** Privacy Policy</a> <input type="hidden" name="agree_to_terms" value="yes"> </label> </div>
Specific Checkbox 2:
<div class="checkbox"> <label id="agree_to_offers_label" for="agree_to_offers" class="visible"> <span class="left-block"> <input id="agree_to_offers" name="agree_to_offers" type="checkbox" data-required-message="" data-change="" checked="checked" value="yes"> <span>By joining *** you'll be notified of exclusive offers and account updates via email</span> </span> </label> </div>
My fruitless attempts:
Xpath:
driver.findElement(By.xpath("//input[@id='agree_to_terms_join' and @type='checkbox']")).click();
Element not visible
driver.findElement(By.xpath("//*[@id='agree_to_terms_join']/parent::label")).click();
Clicks on the href hyperlinks within the div instead
driver.findElement(By.xpath("//*[@id='agree_to_terms_label']/input")).click();
Element not visible
CSS:
driver.findElement(By.cssSelector("input[id = 'agree_to_terms_join'][type = 'checkbox']")).click();
Element not visible
by.className:
driver.findElement(By.className("checkbox")).click();
Opens hyperlinks
I had a look around the forums and saw mention of elements being hidden away - however I can't spot any iframes or anything else that appears to be hiding the bugger?
Any help would be greatly appreciated!!