-1

I'm trying to code an automation function which opens the entered URL. The code works if I'm not working with Chrome browser; but doesn't work with Chrome browser: it fails to detect my Chrome Browser and returns the error "could not find runnable browser".

Code:

import webbrowser

def visitwebsite():
    url = input('Enter url: ')
    webbrowser.get('chrome').open_new_tab(url)

Tried already 'chrome' - 'google-chrome' and redirecting it directly to the path. Maybe i did it wrong

smci
  • 32,567
  • 20
  • 113
  • 146
  • Do you actually want a solution with [tag:python-webbrowser]? in that case this is a duplicate, please see the existing askings. – smci Jan 31 '21 at 05:03
  • What does *"only with the Chrome browser it isnt working"* mean? Does `webbrowser` open IE? try to open Chrome but fail (if so, what exact symptom?)? something else? Does the behavior vary depending on the URL or local file you pass it? Please edit the missing details into the question above. – smci Jan 31 '21 at 05:03
  • Please post the full stacktrace to *error "could not find runnable browser"* so we can see the exact issue in webbrowser. – smci Jan 31 '21 at 05:10
  • Do your failing URLs start with `'http://', 'https://', 'file:/', 'chrome://', ... ` or no prefix at all, e.g. `google.com`? Please post specific examples of failing URLs. – smci Jan 31 '21 at 05:12

1 Answers1

0

The code is simple. You need to install selenium for this.

from selenium import webdriver

driver = webdriver.Chrome(executable_path='path to chromedriver.exe')
driver.get('https://www.google.com)
Abhishek Rai
  • 2,159
  • 3
  • 18
  • 38