Headless Chrome Element is not clickable (works in browser mode)

Issue

I’ve written a script using Selenium, and it works in the browser mode. However, when I try it in Headless mode, it no longer works. I have added arguments to change the window size to my screens resolution; however that still did not resolve the issue. What’s weird is some of the buttons work, but others don’t. Don’t quite know what’s going on.

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
import time
user_input='xyz'
def get_sequence():
    options = Options()
    options.add_argument("--window-size=1920,1080");
    options.add_argument("--start-maximized");
    options.add_argument("--headless");
    driver = webdriver.Chrome(options=options)
    driver.get('https://clims4.genewiz.com/RegisterAccount/Login')
    fill_box = driver.find_element_by_xpath('//*[@id="LoginName"]')
    fill_box.clear()
    fill_box.send_keys('*****')
    fill_box = driver.find_element_by_xpath('//*[@id="Password"]')
    fill_box.send_keys('*****')
    driver.find_element_by_xpath('//*[@id="btnSubmit"]').click()
    table = driver.find_element_by_xpath('//*[@id="myOrdersTable"]/tbody')
    for i,td in enumerate(table.find_elements_by_xpath('//*[@id="myOrdersTable"]/tbody/tr/td[4]'),1):
        if td.text == user_input:
            driver.find_element_by_xpath(f'//*[@id="myOrdersTable"]/tbody/tr[{i}]/td[11]/button').click()
            break

    time.sleep(5)
    seq_list=[]
    table=driver.find_element_by_xpath('//*[@id="gwzSngrOrderResultPanelRoot"]/table/tbody')
    for x,sequence in enumerate(table.find_elements_by_xpath('//*[@id="gwzSngrOrderResultPanelRoot"]/table/tbody/tr/td[9]'),1):
        driver.find_element_by_xpath(f'//*[@id="gwzSngrOrderResultPanelRoot"]/table/tbody/tr[{x}]/td[9]/span[2]').click()
        time.sleep(5)
        seq_info=driver.find_element_by_xpath('//*[@id="gwzViewResultsModalDialog"]/div/div/div[2]/div')
        seq_list.append([seq_info.text])
        driver.find_element_by_xpath('//*[@id="gwzViewResultsModalDialog"]/div/div/div[3]/button').click()
        time.sleep(5)

get_sequence():

The above works if you remove the headless option/arguments. This is the output from the above currently.

[0705/143642.917:INFO:CONSOLE(66)] "visitorResponseData set", source: https://eastprodcdn.azureedge.net/bundles/legacy/velaro.inline.9b226ddb.js (66)
[0705/143644.640:INFO:CONSOLE(3)] "Hotjar not launching due to suspicious userAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/83.0.4103.116 Safari/537.36", source: https://static.hotjar.com/c/hotjar-1144113.js?sv=6 (3)
[0705/143645.765:INFO:CONSOLE(66)] "visitorResponseData set", source: https://eastprodcdn.azureedge.net/bundles/legacy/velaro.inline.9b226ddb.js (66)
 driver.find_element_by_xpath(f'//*[@id="myOrdersTable"]/tbody/tr[{i}]/td[11]/button').click()
  File "C:\Users\Sams PC\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webelement.py", line 80, in click
    self._execute(Command.CLICK_ELEMENT)
  File "C:\Users\Sams PC\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webelement.py", line 633, in _execute
    return self._parent.execute(command, params)
  File "C:\Users\Sams PC\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\Users\Sams PC\AppData\Local\Programs\Python\Python37\lib\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 <button type="button" class="btn btn-sm gwz-grid-action" data-orderid="155e7035-5540-4fc5-8045-247511d0f7dc">...</button> is not clickable at point (1793, 959). Other element would receive the click: <div id="hs-eu-cookie-confirmation" class="hs-cookie-notification-position-bottom" data-nosnippet="">...</div>
  (Session info: headless chrome=83.0.4103.116)

Just thought to add to the readability, this script is just going to a site, search a table within the site for the user_input, then clicking on a button. The new page then contains another table, with a button you click, which generates a pop up containing the data you want to extract.

Edit:
These are the solutions I have attempted:

options = Options()
    options.add_argument("--window-size=1920,1080")
    options.add_argument("--start-maximized")
    options.add_argument("--disable-gpu")
    options.add_argument('--disable-extensions')
    options.add_argument('--no-sandbox')
    options.add_argument("--headless")
    driver = webdriver.Chrome(options=options)

Additionally, the browser window size was 1554,882 in browser mode (when it did work) so I even added:

driver.set_window_size(1554,842)

And it still didn’t work. This is not a browser size issue.

Solution

Resolved the issue, it was a popup regarding the site using cookies. It didn’t show up in browser mode since I had already accepted that popup prior, and the site remembered me. It also didn’t influence the other buttons because it was on the bottom half of the page (overlapping only with one of the buttons, the one that gave the wrror). I was able to use incognito mode to cause to pop up again, and take its element, and add an extra line clicking that button before going on with the rest of my script.

Answered By – samman

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published