0

Though the default browser is IE or Firefox, when I run the program, I want the website to be opened in chrome. At first, I tried this out--

import webbrowser
import os
path = "C:\Program Files (x86)\Google\Chrome\Application %s"
webbrowser.get(path).open("youtube.com")

But the webpage opened in Ie as my default browser is IE.

Then I tried the below code-

from selenium import webdriver
browser =   webdriver.Chrome()
browser.open('https://directory.corp.intranet/cmsviewer/login.html')

But received many errors. Please help me out!!!

  • duplicate : https://stackoverflow.com/questions/22445217/python-webbrowser-open-to-open-chrome-browser – Freeman Feb 12 '20 at 10:58

3 Answers3

2

Hello and welcome to Stack overflow

try to do this :

import webbrowser
chrome_path = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s'
webbrowser.get(chrome_path).open('http://docs.python.org/')

good luck

Freeman
  • 9,464
  • 7
  • 35
  • 58
1

Try maybe the following:

import webbrowser
webbrowser.get('chrome').open("youtube.com")

As it seems that chrome is already registered by default: https://docs.python.org/3.8/library/webbrowser.html#webbrowser.register

Igor Basko
  • 319
  • 2
  • 10
0

Your selenium code is very likely not working due to the lack web extensions like .net, .com,.org, .aspx etc. So your selenium code should work if it looked like

from selenium import webdriver

browser =   webdriver.Chrome()
browser.open('https://directory.corp.intranet.aspx')
maestro.inc
  • 796
  • 1
  • 6
  • 13