0

I recently ran into a problem when trying to scroll websites on a server without GUI, the problem is I can't use ('--headless') option to be able to complete my tests, so I try to open Xvfb fake window not to use this ('--headless') option. Strange thing is that my program works on my local computer with GUI, but when I try to start it from a headless server it will stop when creating chromedriver ( uc.Chrome() ) and will only work with the extra ('--headless') option, that I don't want to use. Is there any solution to this? My program is as following

import undetected_chromedriver as uc
from xvfbwrapper import Xvfb

vdisplay = Xvfb(width=1280, height=740, colordepth=16)
vdisplay.start()

options = uc.ChromeOptions()
options.add_argument('--disable-blink-features=AutomationControlled')
options.add_argument('--incognito')
options.add_argument('--no-default-browser-check')
options.add_argument('--no-first-run')

#program stops here
driver = uc.Chrome(options=options)
    
edgar
  • 1
  • 1
  • I think all you need is "xvfb-run" before "chrome" launch command... you might need to re-write the chromedriver for that? It's going to launch Chrome in devmode.... which you need, but I don't think there's any way to set it to include "xvfb-run". – pcalkins Dec 28 '21 at 22:01
  • come to think of it, you can set the path to Chrome with options.setBinary... I wonder if you could put in something like "path-to-chrome/xvfb-run chrome.exe"?? – pcalkins Dec 28 '21 at 23:35
  • Thank you so much for your response. I am little bit confused, can you please clarify what is the idea, that I should try? I am afraid I am not capable of re-writing chromedriver.. Also do you know what exactly is happening, that it works on my local machine with GUI, but on a server it doesn't transmit the chrome to the xvfb window and just stop and wait infinitely,. – edgar Dec 30 '21 at 12:22
  • I don't know enough about xvfb... but it looks like you have to tell it what to run.... did setting the path to the browser help? Maybe it should be something like "path_to_xvfb/xvfb-run path_to_chrome/chrome"? – pcalkins Dec 30 '21 at 18:12
  • I think this post goes into more details... https://stackoverflow.com/questions/39559186/selenium-grid-xvfb-node-and-jenkins sounds like you need to setup your Selenium grid inside the xvfb server... once that's done it shouldn't need any special run command... you'd just connect to that server. – pcalkins Dec 30 '21 at 18:23
  • Maybe also see this page which uses the run approach I suppose that would be local runs only?: https://ivanderevianko.com/2020/02/xvfb-run-selenium-in-headless-mode-with-any-browser?ref=morioh.com&utm_source=morioh.com – pcalkins Dec 30 '21 at 18:25

0 Answers0