I’m attempting to automate a headless browser to log into a cloud-based payroll system used by my organization. However, it’s failing to proceed past the login phase, while the code functions perfectly in normal mode. Here’s the code I’m working with:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
# Setup Chrome options
options = Options()
options.add_argument('--headless') # Run Chrome in headless mode
options.add_argument('--no-sandbox') # Bypass OS security restrictions
options.add_argument('start-maximized')
options.add_argument('disable-infobars')
options.add_argument('--disable-extensions')
# Initialize WebDriver
browser = webdriver.Chrome(options=options, executable_path='/path/to/chromedriver')
print('Initialized headless Chrome')
# Open the website
browser.get('https://example.com')
print('Accessing website')
# Execute the login process
print('Entering login credentials')
username = '[email protected]'
secret = '*****'
browser.find_element(By.ID, 'usernameField').send_keys(username)
browser.find_element(By.ID, 'passwordField').send_keys(secret)
browser.find_element(By.ID, 'loginButton').click()
print('Attempting login')
# Wait for the next page to load
try:
WebDriverWait(browser, 10).until(EC.presence_of_element_located((By.CLASS_NAME, 'icon-class-name')))
finally:
browser.find_element(By.CLASS_NAME, 'icon-class-name')
I encountered this error:
Traceback (most recent call last):
File "login.py", line 71, in <module>
browser.find_element(By.CLASS_NAME, 'icon-class-name').click()
...
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
It appears the element isn’t interactable. I’m unclear on what this signifies since this function runs successfully when not in headless mode.