[Selenium/python] Help running headless with Chrome profile

BlackxHat

Power Member
Joined
Oct 6, 2009
Messages
729
Reaction score
89
Code:
options = webdriver.ChromeOptions()
options.add_argument('start-maximized')
options.add_argument("--headless")
options.add_argument("user-data-dir=C:\\Users\\sd\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 1\\Default")

driver = webdriver.Chrome(options=options)

If i run it without headless, with my browser open, everything works good. the Chrome profile works and the selenium script runs well.

but if i try to go headless, i get error.

Code:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//input[@type='file']"}
  (Session info: headless chrome=87.0.410.191)
 
Not sure if that's the solution but it might be the size of the window. Try to resize it to your desktop size and see if it works.
 
Not sure if that's the solution but it might be the size of the window. Try to resize it to your desktop size and see if it works.

i removed that line and still get same error
 
Maybe you are trying to find an element before the web page is loading. Try adding a wait() statement like this:

driver.maximize_window();
driver.implicitly_wait(20);
 
Back
Top