My code is very simple: click on a href link to download a file. It works fine until I add the headless argument, then clicking it doesn't do anything. Unsure whether this is a Selenium issue or a Chromedriver issue? None of the solutions I've found online have been helpful, so any suggestions would be appreciated. Here's my code:
import os
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
class Scraper(object):
def __init__(self, cursor):
self.driver = None
def create_driver(self):
# Set up Headless Chrome
chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--start-maximized")
chrome_options.add_argument("--window-size=1920x1080")
self.driver = webdriver.Chrome(executable_path=os.path.abspath("path to chromedriver"),
chrome_options=chrome_options)
self.driver.maximize_window()
def go_to_website(self):
self.driver.get('https://www.abs.gov.au/AUSSTATS/abs@.nsf/DetailsPage/6202.0Nov%202019?OpenDocument')
link_to_click = self.driver.find_element_by_xpath("//a[contains(@href,'/log?openagent&6202012.xls&6202.0')]")
link_to_click.click()
def run(self):
# set a new driver
self.create_driver()
self.go_to_website()