Hi I am accessing an internet database for addresses in Singapore, the idea is to key in the postal code into the search bar and extract the street address in the results page. I have a code that works fine in 'head' mode. But started to have problem in --headless mode. I have a snippet of my code and a snippet of the error message as attached. I'm not too sure what to make of it and hope that you could help me out.
Code:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time
from selenium.webdriver.support.ui import WebDriverWait as wait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
options = Options()
options.headless = True
driver = webdriver.Chrome(executable_path='/Applications/chromedriver', options=options)
driver.get('https://www.streetdirectory.com/')
driver.set_window_position(0,23)
print(driver.title)
time.sleep(3)
wait(driver, 10).until(EC.visibility_of_element_located((By.CLASS_NAME, "btn_close")))
close_ad = driver.find_element_by_class_name('btn_close')
close_ad.click()
searchbar = driver.find_element_by_id('q')
searchbar.send_keys('520123')
wait(driver, 10).until(EC.visibility_of_element_located((By.ID, "search_button")))
findbutton = driver.find_element_by_id('search_button')
findbutton.click()
address = driver.find_element_by_class_name('Link18')
street_address = address.text.split('\n')[0]
print(street_address)
driver.quit()
Error Message:
/Users/cadellteng/venv/bin/python /Users/cadellteng/PycharmProjects/someProject/headlesschrome.py
SG & Singapore Map! Powered by Streetdirectory.com
Traceback (most recent call last):
File "/Users/cadellteng/PycharmProjects/someProject/headlesschrome.py", line 28, in <module>
findbutton.click()
File "/Users/cadellteng/venv/lib/python3.8/site-packages/selenium/webdriver/remote/webelement.py", line 80, in click
self._execute(Command.CLICK_ELEMENT)
File "/Users/cadellteng/venv/lib/python3.8/site-packages/selenium/webdriver/remote/webelement.py", line 633, in _execute
return self._parent.execute(command, params)
File "/Users/cadellteng/venv/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/Users/cadellteng/venv/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="button" id="search_button" onclick="submitSearch();"> is not clickable at point (667, 179). Other element would receive the click: <div id="content_wrapper" style="font-family: arial; height: 592px; position: relative;">...</div>
(Session info: headless chrome=79.0.3945.130)
Process finished with exit code 1