Reputation: 69
I am trying to run a python script that uses webdriver.Remote using CHROME browser in an ubuntu server. I have setup a selenium grid (a hub and a node) in the server and used systemd service files to run the hub and node AND xvfb as background processes. However, running the python file gives me a: selenium.common.exceptions.WebDriverException:
I've been creating fresh droplets and spent countless hours already debugging what is wrong.
[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()
Upvotes: 1
Views: 1259
Reputation: 101
I was having the same error while testing selenium-extras...
I think the latest version (3.4.1) of python-selenium has a bug when interacting with Selenium GRID (hub+node), while running fine when in standalone mode instead.
I worked around it using older python selenium:
pip show selenium | grep -i version
Version: 2.48.0
If you installed with pip, you can uninstall it first:
pip uninstall selenium
then try a different version, I tried with success with the same available from APT:
pip install selenium==2.48.0
Maybe some later versions are working, but did not try.
Bye!
Upvotes: 1