我正在尝试运行一个使用webdriver的python脚本。在ubuntu服务器中使用CHROME浏览器。我在服务器中设置了一个selenium网格(一个集线器和一个节点),并使用systemd服务文件来运行集线器和节点AND xvfb作为后台进程。但是,运行python文件会给我一个:[Unit]
Description=X Virtual Frame Buffer Service
After=network.target
[Service]
ExecStart=/usr/bin/Xvfb :5 -screen 0 1024x768x8
[Install]
WantedBy=multi-user.target
我一直在创造新鲜的水滴,花了无数个小时就已经调试了什么是错的。
[Unit]
Description=Selenium Hub
After=syslog.target network.target
[Service]
User=root
Type=simple
Environment=DISPLAY=:5
ExecStart=/usr/bin/java -Dwebdriver.gecko.driver=/usr/local/bin/geckodriver -Dwebdriver.chrome.bin=/usr/bin/google-chrome -Dwebdriver.chrome.driver=/usr/local/bin/chromedriver -jar /usr/local/bin/selenium-server-standalone.jar -role hub -log /var/log/selenium-hub/output.log
[Install]
WantedBy=multi-user.target
....
[Service]
User=root
Type=simple
Environment=DISPLAY=:5
ExecStart=/usr/bin/java -Dwebdriver.gecko.driver=/usr/local/bin/geckodriver -Dwebdriver.chrome.bin=/usr/bin/google-chrome -Dwebdriver.chrome.driver=/usr/local/bin/chromedriver -jar /usr/local/bin/selenium-server-standalone.jar -role node -hub http://localhost:4444/grid/register -log /var/log/selenium-node/output.log
selenium.common.exceptions.WebDriverException: Message: None
Stacktrace:
at java.util.HashMap.putMapEntries (HashMap.java:500)
at java.util.HashMap.putAll (HashMap.java:784)
at org.openqa.selenium.remote.DesiredCapabilities.<init> (DesiredCapabilities.java:55)
at org.openqa.grid.web.servlet.handler.RequestHandler.process (RequestHandler.java:104)
....
at org.seleniumhq.jetty9.util.thread.QueuedThreadPool.runJob (QueuedThreadPool.java:672
at org.seleniumhq.jetty9.util.thread.QueuedThreadPool$2.run (QueuedThreadPool.java:590
at java.lang.Thread.run (Thread.java:745)
def create_driver():
command_executor = 'http://localhost:4444/wd/hub' # default
capabilities = {
'browserName': 'chrome',
'version': '',
'platform': 'ANY',
'javascriptEnabled': 'True',
# 'acceptSslCerts': 'False',
# 'unexpectedAlertBehaviour': 'True',
'chromeOptions': {
'args': [
'--disable-extensions',
'--no-sandbox',
'--disable-setuid-sandbox',
'--verbose',
'--log-path=/var/log/chromedriver-full.log',
'--disable-impl-side-painting',
'--memory-model=high',
'--disk-cache-size=500000000',
'--allow-running-insecure-content',
'--ignore-certificate-errors',
'--ignore-urlfetcher-cert-requests',
'--disable-gpu',
'--disk-cache-dir=null',
],
# 'extensions': [],
# 'binary': '/usr/bin/chromium-browser',
# 'minidumpPath': '/root/'
},
'loggingPrefs': {'driver': 'ALL', 'server': 'ALL', 'browser': 'ALL', 'performance': 'ALL'}
}
driver = webdriver.Remote(desired_capabilities=capabilities, command_executor=command_executor)
time.sleep(5) # Let the user actually see something!
driver.implicitly_wait(60)
return driver
def main():
print("Running remote web driver test")
driver = create_driver()
driver.get("https://www.google.com.ph")
print(driver.current_url)
screenshot = driver.save_screenshot('/root/test.png')
print(screenshot)
driver.quit()
display.stop()
print("Success test on remote web driver")
main()
npm i --save async
答案 0 :(得分:1)
我在测试selenium-extras时遇到了同样的错误...
我认为python-selenium的最新版本(3.4.1)在与Selenium GRID(集线器+节点)交互时存在错误,而在独立模式下运行正常。
我使用旧版 python selenium:
解决了这个问题pip show selenium | grep -i version
Version: 2.48.0
如果您使用pip安装,则可以先卸载它:
pip uninstall selenium
然后尝试不同的版本,我尝试使用APT提供的相同功能:
pip install selenium==2.48.0
也许某些更高版本正在运行,但没有尝试。
再见!