概述:
我试图在ubuntu服务器上使用CHROME运行一个使用webdriver.Remote的python脚本。我在服务器中设置了selenium网格(集线器和节点),并使用systemd服务文件来运行中心和节点以及作为后台进程的xvfb。但是,运行python文件给我提供了一个:selenium.common.exceptions.WebDriverException:
更多详情:
我一直在制造新的水滴,花了无数个小时来调试出了什么问题。
代码
对于xvfb进程:
[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下面是我的selenium节点的另一个
....
[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)下面是我如何使用remote.WebDriver的方法
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()发布于 2017-05-10 21:14:55
我测试硒的时候也犯了同样的错误.
我认为最新版本(3.4.1)的python在与Selenium (hub+node)交互时存在错误,而在独立模式下运行时运行良好。
我使用老版本的 python完成了它的工作:
pip show selenium | grep -i version
Version: 2.48.0如果您安装了pip,可以先卸载它:
pip uninstall selenium然后尝试另一个版本,我成功地尝试了APT提供的相同版本:
pip install selenium==2.48.0也许一些较晚的版本正在工作,但没有尝试。
再见!
https://stackoverflow.com/questions/43769237
复制相似问题