2

I installed selenium python for both 3 and 2.7 I run the following script:

1) vi test.py:

from selenium import webdriver
import time


chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome('/usr/bin/chromedriver',chrome_options=chrome_options)

driver.get('https://python.org')

I get nothing from the output. If I remove the parameters and leave it basic:

2) vi new.py:

from selenium import webdriver
import time


chrome_options = webdriver.ChromeOptions()
driver = webdriver.Chrome('/usr/bin/chromedriver',chrome_options=chrome_options)

element = driver.get('https://python.org')

I get the following error:

Traceback (most recent call last):
  File "new.py", line 8, in <module>
    driver = webdriver.Chrome('/usr/bin/chromedriver',chrome_options=chrome_options)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
    desired_capabilities=desired_capabilities)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
  (Driver info: chromedriver=2.41.578700 (2f1ed5f9343c13f73144538f15c00b370eda6706),platform=Linux 4.18.0-10-generic x86_64)

I installed: snap install chromium sudo apt-get install chromium-browser chromium-chromedriver pip install selenium

inrob
  • 4,969
  • 11
  • 38
  • 51
  • Did you install Chrome browser? – Ratmir Asanov Jan 30 '19 at 09:13
  • @inrob try only this, `from selenium import webdriver driver = webdriver.Chrome("/usr/bin/chromedriver"); driver.get("https://www.google.co.in/search?q=stackoverflow")`. don't pass empty options also – Ali Jan 30 '19 at 09:30
  • sudo apt-get install chromium-browser chromium-chromedriver – inrob Jan 30 '19 at 09:31
  • @AliCSE Can I give you my root pass in private for this test server? I get error (unknown error: DevToolsActivePort file doesn't exist) – inrob Jan 30 '19 at 10:14
  • @inrob Already the answer is there for this question, refer [This Link](https://stackoverflow.com/questions/53073411/selenium-webdriverexceptionchrome-failed-to-start-crashed-as-google-chrome-is) or [This Link](https://stackoverflow.com/questions/52009351/the-process-started-from-chrome-location-c-chrome-application-chrome-exe-is) and let's see what will happen – Ali Jan 30 '19 at 10:28
  • @AliCSE, Where do i download package to be saved at .... /chrome/binary/ I am on ubuntu 18.4 – inrob Jan 30 '19 at 10:41
  • @inrob For installing the chrome, refer [this link](https://www.linuxbabe.com/ubuntu/install-google-chrome-ubuntu-18-04-lts) – Ali Jan 30 '19 at 10:52
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/187563/discussion-between-ali-cse-and-inrob). – Ali Jan 30 '19 at 10:55

1 Answers1

0
  1. It's normal do not see the driver (automated browser) during the headless mode.
  2. Try to install Chrome browser (your second script):

wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome-stable_current_amd64.deb

Hope it helps you!

Ratmir Asanov
  • 6,237
  • 5
  • 26
  • 40
  • 1
    sudo apt-get install chromium-browser chromium-chromedriver – inrob Jan 30 '19 at 09:31
  • @inrob, check, please, my updated answer. – Ratmir Asanov Jan 30 '19 at 09:37
  • sudo dpkg -i google-chrome-stable_current_amd64.deb OUTPUTS: dpkg: error: cannot access archive 'google-chrome-stable_current_amd64.deb': No such file or directory – inrob Jan 30 '19 at 10:09
  • You need to download first the .deb-package. See my updated answer. Thanks. – Ratmir Asanov Jan 30 '19 at 11:10
  • How is going? Did you try my last update? – Ratmir Asanov Jan 30 '19 at 13:08
  • Hi. this:https://pastebin.com/raw/qsxnmdkq Doesnt work. Neither does this https://pastebin.com/raw/Qhx10upU but this works: https://pastebin.com/raw/S707uKFv Any ideas? Also are you available for consulting? – inrob Jan 30 '19 at 13:44
  • Did it fix your problem? Is it a virtual machine with Ubuntu? – Ratmir Asanov Jan 30 '19 at 13:48
  • Ubuntu 18.04, testing machine, if you want I can give login details to check. At least the last example works. I needed one working example.However when I connect with vnc it shows gray screen – inrob Jan 30 '19 at 13:52
  • So, you do not have a monitor for this machine? In this case, it will work only in headless mode (when your browser physically is not visible). If my answer is fixed your asked above problem -- you can accept my answer (check a tick near my answer). Thanks. – Ratmir Asanov Jan 30 '19 at 13:56
  • I mean monitor as the physical display. – Ratmir Asanov Jan 30 '19 at 14:06
  • Nope, just a vultr vps is all I have. I used to do it before, the same way – inrob Jan 30 '19 at 14:23
  • @inrob, in this case, you can run only in headless mode. – Ratmir Asanov Jan 30 '19 at 14:34
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/187586/discussion-between-inrob-and-ratmir-asanov). – inrob Jan 30 '19 at 15:12