Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

[Selenium/python] Help running headless with Chrome profile

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. pls help i am noob

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)
Might be loading the page too fast. Try looking into this.

https://selenium-python.readthedocs.io/waits.html
Just like Nyan said, you need to wait for the page to load either with a delay (dirty) or you should wait for the specific element you want:

PHP Code

<?php 
wait 
= WebDriverWait(driver, 10)
element = wait.until(element_condition) 


The "element_condition" can be the element itself that you're looking for once it appears on the page, or you can use an "expected condition" from the "selenium.webdriver.support.expected_conditions". There are several you can use. I use this for a LinkedIn scraper, just as an example, and it works great.
Malware Dev & Grey Hat available for contract work. DM if you need me.
OSCP, OSCE, OSEE, OSWE, OSWP, CEH, CISSP
Yeah, I've been around a while


Possibly Related Threads...
Thread / Author Replies Views Last Post
by MagickDec 16, 2023 04:27 PM 16 474 Dec 16, 2023 04:27 PM
Last Post: Apricus
[Python] by Luffy-_-Aug 20, 2023 02:06 AM 12 446 Aug 20, 2023 02:06 AM
Last Post: Lucky4L
[Python] by Bass_ReevesAug 20, 2023 01:44 AM 9 631 Aug 20, 2023 01:44 AM
Last Post: Lucky4L