Does Selenium need display monitor

房东的猫 提交于 2021-01-28 20:11:41

问题


I am using Selenium to open a web site, login and copy some information from one web site. However it is happening on my work station and have a display monitor.

my IT team wants to move this process to a virtual server which does not have a monitor.

1.Will this work - even if we install Chrome of Firefox on the server 2. Can we Chrome - headless to make this happen 3. Any other way - we can think of using Xserver

Please let me know.


回答1:


Chrome headless should solve your problem here -- I've done this in the past with some of my automation and had success.

Just remember to use ChromeOptions to add the --headless flag. You may need to tweak some other ChromeOptions as well -- I also had to add --disable-gpu and --window-size=1920,1200 to get mine working just right.




回答2:


No . To run your script you don't need to have monitor. You can access your virtual machine through remote connection and you can start the execution from that machine. Once the execution started, you can close the remote desktop session and execution will continue to run on remote machine or virtual server.

I hope this helps. Please let me know if you have any further questions.

1.Will this work - even if we install Chrome or Firefox on the server - Yes it will work

2.Can we Chrome - headless to make this happen - If you are going to use virtual server just for execution,then you don't need to run in headless mode. Headless execution is needed for environments where you don't need a visible UI shell. Below code will help you run your script in headless mode

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument('--headless')
options.add_argument('--disable-gpu')  # Last I checked this was necessary.
driver = webdriver.Chrome("/usr/local/bin/chromedriver", chrome_options=options)
driver.get("https://google.com")
#code to extract the details
driver.quit()

3.Any other way - we can think of using Xserver - Not sure



来源:https://stackoverflow.com/questions/58329031/does-selenium-need-display-monitor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!