1

Hi guys i was trying to click this checkbox :

<label class="has-checkbox terms"><input name="order[terms]" type="hidden" value="0" /><input class="checkbox" type="checkbox" value="1" name="order[terms]" id="order_terms" />I have read and agree to the <a href="http://www.supremenewyork.com/shop/terms">terms & conditions</a>, and accept the return policy<span class="terms-error">please agree to the terms</span></label></p><div class="g-recaptcha" data-callback="checkoutAfterCaptcha" data-sitekey="AAAA3423" data-size="invisible"></div><input id="number_v" name="hpcvv" /></fieldset></div></div><div id="cart-footer"><div id="pay"><p style="">Surgelati</p><input type="submit" name="commit" value="process payment" class="button checkout" disable_with="processing, please wait..." /><a class="button cancel" href="http://www.altervista.com/shop">cancel</a></div></div></form></div><div id="surchage_info_tooltip">Vendita 

I have tried with :

from selenium.webdriver.common.action_chains import ActionChains

element = driver.find_element_by_id("order_terms")

actions = ActionChains(driver)
actions.move_to_element(element).perform()
driver.execute_script("arguments[0].click();", element)
element = driver.find_element_by_id('order_terms').click()

driver.find_element_by_class_name("has-checkbox terms").click()
driver.find_element_by_xpath(".//*[contains(text(), 'I have read and agree to the')]").click()

Every of this codes but no-one of them works....

This works

actions.move_to_element(element).perform()

partially because the checkbox appear to have the mouse on it , but it doesn't click , can you help me ?

1
  • 1
    Can you share page URL? Commented Sep 13, 2018 at 20:36

2 Answers 2

1

Chaining your actions together might help solve this problem. Combine move_to_element action with click before calling the perform() method.

from selenium.webdriver.common.action_chains import ActionChains
element = driver.find_element_by_id("order_terms")
actions = ActionChains(driver)
action.move_to_element(element).click(element).perform()

OR simply

action.move_to_element(element).click().perform()
Sign up to request clarification or add additional context in comments.

Comments

1

As per the HTML you have shared to invoke click() on the checkbox you can use either of the following solutions:

  • CSS_SELECTOR:

    driver.find_element_by_css_selector("label.has-checkbox.terms input.checkbox#order_terms").click()
    
  • XPATH:

    driver.find_element_by_xpath("//label[@class='has-checkbox terms']//input[@class='checkbox' and @id='order_terms']").click()
    

Update

As you are seeing the error Other element would receive the click you can adopt either of the following solutions:

  • Induce WebDriverWait:

    • CSS_SELECTOR:

      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "label.has-checkbox.terms input.checkbox#order_terms"))).click()
      
    • XPATH:

      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//label[@class='has-checkbox terms']//input[@class='checkbox' and @id='order_terms']"))).click()
      
  • Using WebDriverWait and ActionChains:

    • CSS_SELECTOR:

      myElement = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "label.has-checkbox.terms input.checkbox#order_terms")))
      ActionChains(driver).move_to_element(myElement).click(myElement).perform()
      
    • XPATH:

      myElement = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//label[@class='has-checkbox terms']//input[@class='checkbox' and @id='order_terms']")))
      ActionChains(driver).move_to_element(myElement).click(myElement).perform()
      

2 Comments

it says : Message: unknown error: Element <input class="checkbox" type="checkbox" value="1" name="order[terms]" id="order_terms" style="position: absolute; top: -20%; left: -20%; display: block; width: 140%; height: 140%; margin: 0px; padding: 0px; background: rgb(255, 255, 255); border: 0px; opacity: 0;"> is not clickable at point (532, 511). Other element would receive the click: <ins class="iCheck-helper" style="position: absolute; top: -20%; left: -20%; display: block; width: 140%; height: 140%; margin: 0px; padding: 0px; background: rgb(255, 255, 25); border: 0px; opacity: 0;"></ins>
@Marià Checkout my updated answer and let me know the status

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.