Using Specific Browsers with the Webbrowser Module

Fixed my issue where the blog link in Nucleus would point to IE instead of chrome!

def open_webpage(self, webpage):
    webbrowser.register('chrome', None, webbrowser.GenericBrowser("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"))
    webbrowser.get('chrome').open(webpage, new = 0, autoraise = True)

By using the register function and adding a reference to a predefined browser, a constructor (which can be None because we’ve provided an instance) and an instance. The instance is using the GenericBrowser function to open our browser executable.

This of course wouldn’t work if I was rolling out the tool to others, I’d need to use the %PROGRAMFILES(x86)% environment variable to find path.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s