Search code examples
selenium-webdriverselenium-chromedriverweb-crawlergoogle-chrome-headless

Element not Interactable - Selenium headless chrome=115.0.5790.170 - How to solve this?


I'm having a problem using selenium with the headless chrome=115.0.5790.170, I have a table and a td with this a tag.

<a id="formSegundaViaFatura:dtListaSegundaViaFaturaDebitoPendente:0:j_idt64" href="#" class="ui-commandlink ui-widget" onclick="PrimeFaces.addSubmitParam('formSegundaViaFatura',{'formSegundaViaFatura:dtListaSegundaViaFaturaDebitoPendente:0:j_idt64':'formSegundaViaFatura:dtListaSegundaViaFaturaDebitoPendente:0:j_idt64'}).submit('formSegundaViaFatura');return false;">2 via</a>

This code will operate in a VM without graphic resources, only the terminal, that's why I need the headless. But when I Try to interact in specific with this element sending a click(), an error is launched.

Message: element not interactable (Session info: headless chrome=115.0.5790.170) Stack trace:

If someone knows how I can avoid this error and interact with this element I'll be really grateful, because it's the last piece to make this crawler work with headless mode.

Ok! Some news, when I check if the element is displayed element.is_displayed() using the headless flag, it shows the element is not displayed sending False but when the headless flag is not allowed it says True the element is displayed.


Solution

  • Problem solved. How I've found a way to fix this problem? So the problem was when the --headless flag is used, because in this case the element that I was trying to click doesn't seems to be visible. So, using chat GPT it sugests to execute the javascript function on the element and not to click on it.

    element = driver.find_element(By.ID, id_element) driver.execute_script("arguments[0].click();", element)

    some auxiliary flags that I use to configure my driver Options and helped to fix the problem:

    driver_options.add_experimental_option("prefs", {
                    "download.default_directory": download_folder_path,
                    "download.prompt_for_download": False,
                    "download.directory_upgrade": True,
                    "safebrowsing.enabled": True
                })
    

    So, using the context on top, I got what I want.