1

I am trying to create a user with Selenium because I don't have access to the database from my server. I get the message "PASS" but the user is never created so I thing it might be something related to headless.

Is there any way to use clicks and filling forms with headless?

Setup

chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-gpu')
chrome_service = ChromeService('/home/bitnami/chromedriver')
driver = webdriver.Chrome(service=self.chrome_service,options=self.chrome_options)

Create user

driver.get(URL)
driver.set_window_size(1657, 1006)
driver.find_element(By.ID, "username").send_keys(USER)
driver.find_element(By.ID, "password").send_keys(PASS)
driver.find_element(By.ID, "_submit").click()
driver.find_element(By.LINK_TEXT, "Ajustes").click()
driver.find_element(By.CSS_SELECTOR, "#administrator-salespersons span").click()
driver.find_element(By.CSS_SELECTOR, ".fa-plus").click()
driver.find_element(By.CSS_SELECTOR, ".btn-sm").click()
driver.find_element(By.ID, "sal_username").send_keys(USER2)
driver.find_element(By.ID, "sal_password").send_keys(PASS2)
driver.find_element(By.ID, "sal_email").send_keys(EMAIL)
driver.find_element(By.ID, "sal_Guardar").click()
driver.quit()

Note: I've tested in my computer without headless and it creates the user successfully. I don't get any error in the server. I've also searched all over the internet but all I've found are examples without clicks.

Successful message after running pytest

rami
  • 15
  • 3

1 Answers1

1

Instead of:

chrome_options.add_argument("--headless")

try:

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

Note

The prerequisite to use Native Headless mode i.e. --headless=new which is now officially called the new Headless mode are as follows:

aptly supported through:


References

You can find a couple of relevant detailed discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • why in my selenium 4.8 with chromedriver version 109.0.5414.74, unable to execute that arguments? Seems here the headless keep runing as normal instead of real headless. @undetectedSelenium – gumuruh Mar 23 '23 at 06:37