I've been puzzling at this for a few hours now. Checked through similar issues on Stackoverflow but been unable to find a solution.
I have a checkbox I'm trying to use Selenium webdriver to check, but when I run the script, I don't get any error messages but the checkbox remains unchecked.
I'm using the line below to select and check the box
IWebElement checkBox = m_driver.FindElement(By.XPath("//div[2]/label/span"));
checkBox.Click();
I've copied the HTML from it below.
<div class="input-group single-option label-empty" >
<label class="" >
<input type="checkbox" name="privacy" value="true" required />
<span>I have read and understood the <a data-toggle="#privacy-terms"
data-group="privacy-terms">Privacy Policy</a> and <a data-toggle=
"#terms" data-group="privacy-terms">Terms and Conditions</a>. </span>
</label>
I'd really be grateful for some help. I'm pretty new to automation...and C#
Unfortunately, I am unable to post the url as it's a passworded client site. If I can post the HTML, that may help...
I've posted the html from the page in question but removed the client name :)
If I select the checkbox through Chrome developer tools and copy the Xpath, I get this.
IWebElement checkBox = m_driver.FindElement(By.XPath("/html/body/div[1]/main/section/form/div[2]/label/input"));
I re-ran it and Selenium generated an error.
Message: OpenQA.Selenium.WebDriverException : unknown error: Element is not clickable at point (491, 593). Other element would receive the click: ... (Session info: chrome=71.0.3578.98) (Driver info: chromedriver=2.45.615291 (ec3682e3c9061c10f26ea9e5cdcf3c53f3f74387),platform=Windows NT 10.0.17134 x86_64)
Here is a screenshot of developer tools with the checkbox ticked. Could it be something to do with the 'span'?
"//input[@type='checkbox'][@name='privacy']"try this xpath