Reputation: 3
I am trying to select the checkbox that appear on an HTML page with Python 3.7 and Selenium. The final goal is obviously to manipulate them, but I can't even manage to select it properly. The url is the following:
https://eurexmargins.prod.dbgservice.com/
Prior to that post, I carefully read the related page but the proposed solutions don't work in my case (I get an ElementClickInterceptedException).
Here is my code:
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
browser = webdriver.Chrome('C:\Program Files\chromedriver_win32\chromedriver.exe')
MAX_TIMEOUT = 20
def get_element(by_arg, by_method=By.ID):
return WebDriverWait(browser, MAX_TIMEOUT).until(
EC.presence_of_element_located((by_method, by_arg))
)
browser.switch_to_default_content()
browser.get("https://eurexmargins.prod.dbgservice.com/")
get_element(".//input[@type='checkbox']", By.XPATH).click()
time.sleep(15)
browser.quit()
Thanks for any help.
Upvotes: 0
Views: 123
Reputation: 3790
The issue is that this is not your regular check box. See below for a working example.
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium import webdriver
driver = webdriver.Chrome("C:\Program Files\chromedriver_win32\chromedriver.exe")
driver.get("https://eurexmargins.prod.dbgservice.com/terms")
element_toclick = WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.XPATH, "//mat-checkbox[@id='mat-checkbox-1']")))
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
element_toclick.click()
Upvotes: 1