kaliiiiiiiiii / Selenium-Driverless

undetected Selenium without usage of chromedriver
https://kaliiiiiiiiii.github.io/Selenium-Driverless/
Other
545 stars 66 forks source link

Can't find element using XPATH while headless #237

Closed ahihiyou20 closed 3 months ago

ahihiyou20 commented 3 months ago

Reproducing the issue:

# Will not run with headless
options = driver.webdriver.ChromeOptions()
options.add_argument("--headless")

# Window's size also affect find_element
driver.set_window_rect(1,1,1,1) # Will also broke find_element 

button = await driver.find_element(
            by=By.XPATH, value='//a[@href="/bot/408785106942164992/vote"]'
)
# TimeoutError: Couldn't compute element location within 30 seconds

I doubt if this is the library's fault to blame since other selenium drivers won't work as well, if this is the case then can you give some tips? How do I make find_element work in headless?

In addition to that, It seems like the library will unlikely bypass cloudflare in headless mode, It's not impossible but sometimes cloudflare can still refuse to let me proceed. Are there any solutions too?  

ahihiyou20 commented 3 months ago

It works like a charm in normal mode (just to clarify)

kaliiiiiiiiii commented 3 months ago

verry likely, this is due to detection. You can test that by saving a screenshot. Try using options.headless = True instead (less detectable)

ahihiyou20 commented 3 months ago

And that worked perfectly! Thanks for your fast reply!