kaliiiiiiiiii/Selenium-Driverless

Can't find element using XPATH while headless

ahihiyou20 opened this issue · 3 comments

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?  

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

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

And that worked perfectly! Thanks for your fast reply!