-1
import pandas as pd
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException
from pandas.io.html import read_html
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys 
import time
from bs4 import BeautifulSoup

url = 'https://www.globenewswire.com/Search/NewsSearch?keyword=complete%20response%20letter&icb=4570&subjectCode=Company%20Announcement'

def CRL_Updater():
    options = Options()
    options.headless = False
    driver = webdriver.Chrome('/Users/sajjad/Downloads/chromedriver', options=options)
    driver.get(url)
    driver.find_element_by_xpath('/html/body/div[2]/div/a[1]/i[1]').click()
    time.sleep(0.5)
    search_bar = driver.find_element_by_xpath('//*[@id="quicksearch-textbox"]')
    search_bar.send_keys('complete response letter')
    search_bar.send_keys(Keys.ENTER)
    time.sleep(1)
    industry_box = driver.find_element_by_id('facetfield_Icb_4570').click()
    time.sleep(1)
    subject_box =  driver.find_element_by_id('facetfield_SubjectCode_Company_Announcement').click()

    


CRL_Updater()

Here is my code. Essentially everytime I write ANYTHING after the subject_box = driver.find_element_by_id('facetfield_SubjectCode_Company_Announcement').click() line, I get the following error,

File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <input type="checkbox" id="facetfield_Icb_4570" name="facetfield_Icb" value="4570"> is not clickable at point (27, 588). Other element would receive the click: <div class="action-container">...</div>
  (Session info: chrome=87.0.4280.88)

I've used selenium on other sites before and done similar things but I never had an issue like this. It seems every time I add anything after that statement I get this error and I'm not entirely sure why. When I do add what I want to do next, my code takes me up until the checkbox lines, and stops there claiming it won't click. Why can it click it before I add more code but not after?

2 Answers2

0

maybe the element is not ready when you click it. Try this,

import pandas as pd
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException
from pandas.io.html import read_html
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys 
import time
from bs4 import BeautifulSoup
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

url = 'https://www.globenewswire.com/Search/NewsSearch?keyword=complete%20response%20letter&icb=4570&subjectCode=Company%20Announcement'

def CRL_Updater():
    options = Options()
    options.headless = False
    driver = webdriver.Chrome('/Users/sajjad/Downloads/chromedriver', options=options)
    driver.get(url)
    driver.find_element_by_xpath('/html/body/div[2]/div/a[1]/i[1]').click()
    time.sleep(0.5)
    search_bar = driver.find_element_by_xpath('//*[@id="quicksearch-textbox"]')
    search_bar.send_keys('complete response letter')
    search_bar.send_keys(Keys.ENTER)
    time.sleep(1)
    industry_box = driver.find_element_by_id('facetfield_Icb_4570').click()
    time.sleep(1)
    subject_box = WebDriverWait(driver, 20).until(
    EC.element_to_be_clickable((By.ID, "facetfield_SubjectCode_Company_Announcement")))
    subject_box.click()


CRL_Updater()
wetler
  • 374
  • 2
  • 11
0

That depends on what happens on the page because the element could be intercepted by another element or not properly loaded; in this case, it is more likely that the element is intercepted but to avoid both cases you can use WebDriverWait and Javascript combined in order to wait for the element to be clickable and to be able to click the element even if it is intercepted:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as ec

subject_box =  WebDriverWait(driver, 10).until(ec.element_to_be_clickable((By.ID, 'facetfield_SubjectCode_Company_Announcement')))
driver.execute_script("arguments[0].click();", subject_box)
marco
  • 525
  • 4
  • 11