5

enter image description hereI am a newbie to selenium just trying to learn. When tried opening Chrome browser through ChromeDriver I got the below error:

Traceback (most recent call last):
  File "selenium_practise1_chrome.py", line 5, in <module>
    driver = webdriver.Chrome()
  File "C:\Users\kulokesh\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 75, in __init__
    desired_capabilities=desired_capabilities)
  File "C:\Users\kulokesh\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 156, in __init__
    self.start_session(capabilities, browser_profile)
  File "C:\Users\kulokesh\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 251, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "C:\Users\kulokesh\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 320, in execute
    self.error_handler.check_response(response)
  File "C:\Users\kulokesh\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: unable to discover open pages
  (Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=a lotows NT 6.1.7601 SP1 x86_64)

Tried alot of googling but nothing helped. Below is my code:

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.common.keys import Keys

driver = webdriver.Chrome()
driver.get('http://www.python.org')
print(driver.title)

This is not a code to deal with but I am confused what am I missing here. Also please suggest some good online resource to learn Python Selenium. My chrome opened was looking like below:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
k.lo
  • 403
  • 2
  • 5
  • 13
  • 1
    Possible duplicate of [Chrome Driver Error using Selenium: Unable to Discover Open Pages](https://stackoverflow.com/questions/21001652/chrome-driver-error-using-selenium-unable-to-discover-open-pages) – timbre timbre Sep 06 '18 at 16:40

1 Answers1

10

This error message...

selenium.common.exceptions.WebDriverException: Message: unknown error: unable to discover open pages
  (Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=a lotows NT 6.1.7601 SP1 x86_64)

...implies that the ChromeDriver was unable to initiate/spawn a new WebBrowser i.e. Chrome Browser session.


Solution

Add the argument --no-sandbox through ChromeOptions() to your existing code as follows:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument('--no-sandbox') # Bypass OS security model
driver = webdriver.Chrome(chrome_options=options, executable_path=r'C:\path\to\chromedriver.exe')
driver.get('http://www.python.org')
print(driver.title)
driver.quit()

Additional considerations

  • Upgrade Selenium to current levels Version 3.14.0.
  • Upgrade ChromeDriver to current ChromeDriver v2.41 level.
  • Keep Chrome version between Chrome v66-68 levels. (as per ChromeDriver v2.41 release notes)
  • Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
  • Execute your @Test.
  • Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Nothing helped still same issue "selenium.common.exceptions.WebDriverException: Message: unknown error: unable to discover open window in chrome (Session info: chrome=67.0.3396.79) (Driver info: chromedriver=2.41.578737 (49da6702b16031c40d63e5618de03a32ff6c197e),platform=Windows NT 6.1.7601 SP1 x86_64)" – k.lo Sep 07 '18 at 09:15
  • 1
    Checkout my updated answer and let me know the status. – undetected Selenium Sep 07 '18 at 09:33
  • 1
    Works like a charm thank you. Can you suggest me best resource to learn Selenium in Python. – k.lo Sep 07 '18 at 09:40
  • 1
    @k.lo Officially [Selenium Documentation](https://seleniumhq.github.io/selenium/docs/api/py/api.html) and unofficially [WebDriver API](https://selenium-python.readthedocs.io/api.html#) are the best documents to learn Selenium in Python. – undetected Selenium Sep 07 '18 at 09:56
  • 1
    This answer does not explain what `--no-sandbox` does nor why it fixes the issue. Obviously this answer suggest disabling a security feature that's enabled by default. Generally this is an indication of a bad solution. This answer needs to be improved. – Claus May 17 '20 at 18:04
  • This is occurring for me in electron development, is it possible that i have a wrong version of my electron and electron-chromedriver versions match, could it be affected by the version of chrome installed on my computer? i'm lost for ideas on why it is failing on this call in the vanilla built-in electron spectron implementation – Jody Sowald Nov 06 '20 at 00:51
  • @JodySowald Let's discuss in details within [Selenium Chat Room](https://chat.stackoverflow.com/rooms/223360/selenium) – undetected Selenium Nov 09 '20 at 11:53
  • @DebanjanB Thanks, sorry i didn't get back to you then, I've decided to cut spectron(the thing that uses chromedrivers) out of the mix. its recommended but doesn't seem to serve a purpose aside from separating the tests from the main code, which we can organize for just fine. – Jody Sowald Nov 11 '20 at 13:57