idiot one
idiot one

Reputation: 389

Selenium - Element is not clickable at point because another element obscures it

I am using following code to download the excel from this web site, the code was working fine but recently the web page may change so my code doesn't work. It returns this error:

selenium.common.exceptions.ElementClickInterceptedException: Message: Element is not clickable at point (1250,464) because another element obscures it

Here is the code:

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

geckodriver = '/opt/geckodriver'

options = webdriver.FirefoxOptions()
options.add_argument('-headless')

driver = webdriver.Firefox(executable_path=geckodriver, firefox_options=options)

driver.get('https://www.hkex.com.hk/Market-Data/Futures-and-Options-Prices/Equity-Index/Hang-Seng-Index-Futures-and-Options?sc_lang=en#&product=HSI')

WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, 'ete'))).click()
time.sleep(2)

html = driver.page_source

print(html)

I searched the posts in stackoverflow, I found that I can use ActionChains but I dunno how to apply to until(EC.element_to_be_clickable((By.ID, 'ete')))

ActionChains(driver).move_to_element(element).click().perform()

Upvotes: 0

Views: 243

Answers (1)

undetected Selenium
undetected Selenium

Reputation: 193308

Possibly the Cookie Concent Banner obscures the click.


Solution

Click on Accept button first adding the argument --headless=new and you can download the excel inducing WebDriverWait for the element_to_be_clickable() and you can use the following locator strategies:

  • Code Block:

    from selenium import webdriver
    from selenium.webdriver.chrome.options import Options
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
    options = Options()
    options.add_argument('--headless=new')
    options.add_argument("start-maximized")
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.hkex.com.hk/Market-Data/Futures-and-Options-Prices/Equity-Index/Hang-Seng-Index-Futures-and-Options?sc_lang=en#&product=HSI")
    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button#onetrust-accept-btn-handler"))).click()
    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "#ete"))).click()
    

Upvotes: 0

Related Questions