0

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.

  • element not interactable means some other element is blocking on top of your element, check for any popup and verify that your element is clickable – Darkknight Aug 16 '23 at 15:57

2 Answers2

0

If your issue is caused by using headless Chrome, then you try using Chrome's newer headless mode, which is activated like this:

options.add_argument("--headless=new")

In a full script, that looks like this:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service

service = Service()
options = webdriver.ChromeOptions()
options.add_argument("--headless=new")
driver = webdriver.Chrome(service=service, options=options)
# ... This is where you automate things...
driver.quit()

Your automation will now get the same results in new headless mode as regular headed Chrome.

Michael Mintz
  • 9,007
  • 6
  • 31
  • 48
  • I changed to the selenium 4.11.0, put the '--headless=chrome' flag. But it still not working. Keeps sending the menssage 'Element not Interactable'. Its really strange because without the headless the full script works,the element can be found, but with the headless it doesn't. I'm using beautiful soup to extract the id from the element, because in the table we can have many. And with a for loop the selenium interact with each . – Igor Brizack Aug 16 '23 at 16:25
  • I meant `--headless=new` - https://stackoverflow.com/a/73840130/7058266 (The other one was renamed recently.) – Michael Mintz Aug 16 '23 at 18:39
  • Thanks for your help, I really aprecciate. I found a solution, you can check on the answer below. Still using '--headless=chrome' . – Igor Brizack Aug 16 '23 at 19:15
0

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.