Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Selenium open URL in same Firefox window

I am using Python Selenium to open a Firefox browser and go to a URL. The function I am using to do this is...

def openurl_function():
    from selenium import webdriver
    from selenium.common.exceptions import NoSuchElementException
    from selenium.webdriver.common.keys import Keys

    from selenium import webdriver
    driver = webdriver.Firefox()
    driver.get('http://www.example.com')

When I run the function it always opens a new instance of FireFox, is there a way to have it to just open using the same browser instance?

Currently if I run the function 10 times then I get 10 FireFox browsers open.

like image 846
fightstarr20 Avatar asked Feb 24 '16 18:02

fightstarr20


1 Answers

Just keep reusing the same driver. You are creating a new browser, every time you call

driver = webdriver.Firefox()

Also, because you never quit() on your driver, you will probably have all the browsers stay open as orphans because you deleted the handle to them when you created a new browser.

like image 112
jsfan Avatar answered Nov 16 '22 14:11

jsfan