collinsanele

Fix and download Chromedriver on Ubuntu!

Apr 1st, 2020
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. Copy and paste the below scripts
  2.  
  3.  
  4. #!/usr/bin/env bash
  5. # https://developers.supportbee.com/blog/setting-up-cucumber-to-run-with-Chrome-on-Linux/
  6. # https://gist.github.com/curtismcmullan/7be1a8c1c841a9d8db2c
  7. # http://stackoverflow.com/questions/10792403/how-do-i-get-chrome-working-with-selenium-using-php-webdriver
  8. # http://stackoverflow.com/questions/26133486/how-to-specify-binary-path-for-remote-chromedriver-in-codeception
  9. # http://stackoverflow.com/questions/40262682/how-to-run-selenium-3-x-with-chrome-driver-through-terminal
  10. # http://askubuntu.com/questions/760085/how-do-you-install-google-chrome-on-ubuntu-16-04
  11.  
  12. # Versions
  13. CHROME_DRIVER_VERSION=`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE`
  14. SELENIUM_STANDALONE_VERSION=3.4.0
  15. SELENIUM_SUBDIR=$(echo "$SELENIUM_STANDALONE_VERSION" | cut -d"." -f-2)
  16.  
  17. # Remove existing downloads and binaries so we can start from scratch.
  18. rm ~/google-chrome-stable_current_amd64.deb
  19. rm ~/selenium-server-standalone-*.jar
  20. rm ~/chromedriver_linux64.zip
  21. sudo rm /usr/local/bin/chromedriver
  22. sudo rm /usr/local/bin/selenium-server-standalone.jar
  23.  
  24. # Install dependencies.
  25. sudo apt-get update
  26. sudo apt-get install -y unzip openjdk-8-jre-headless xvfb libxi6 libgconf-2-4
  27.  
  28. # Install Chrome.
  29. wget -N https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb -P ~/
  30. sudo dpkg -i --force-depends ~/google-chrome-stable_current_amd64.deb
  31. sudo apt-get -f install -y
  32. sudo dpkg -i --force-depends ~/google-chrome-stable_current_amd64.deb
  33.  
  34. # Install ChromeDriver.
  35. wget -N http://chromedriver.storage.googleapis.com/$CHROME_DRIVER_VERSION/chromedriver_linux64.zip -P ~/
  36. unzip ~/chromedriver_linux64.zip -d ~/
  37. rm ~/chromedriver_linux64.zip
  38. sudo mv -f ~/chromedriver /usr/local/bin/chromedriver
  39. sudo chown root:root /usr/local/bin/chromedriver
  40. sudo chmod 0755 /usr/local/bin/chromedriver
  41.  
  42. # Install Selenium.
  43. wget -N http://selenium-release.storage.googleapis.com/$SELENIUM_SUBDIR/selenium-server-standalone-$SELENIUM_STANDALONE_VERSION.jar -P ~/
  44. sudo mv -f ~/selenium-server-standalone-$SELENIUM_STANDALONE_VERSION.jar /usr/local/bin/selenium-server-standalone.jar
  45. sudo chown root:root /usr/local/bin/selenium-server-standalone.jar
  46. sudo chmod 0755 /usr/local/bin/selenium-server-standalone.jar
  47.  
  48.  
  49.  
  50.  
  51. #Sample python script with selenium
  52. import time
  53. from selenium import webdriver
  54. from pyvirtualdisplay import Display
  55.  
  56.  
  57.  
  58. #Important
  59.  
  60. display = Display(visible=0, size=(800, 600))
  61. display.start()
  62.  
  63.  
  64. driver = webdriver.Chrome('/usr/lib/chromium-browser/chromedriver') # Optional argument, if not specified will search path.
  65. # or '/usr/lib/chromium-browser/chromedriver' if you use chromium-chromedriver
  66. driver.get('http://www.putty.org');
  67. time.sleep(5) # Let the user actually see something!
  68. print("Good")
  69. driver.quit()
Add Comment
Please, Sign In to add comment