How use a running instance of Firefox

797 views
Skip to first unread message

Jim Byrnes

unread,
Nov 1, 2016, 7:10:40 PM11/1/16
to seleniu...@googlegroups.com
Using python is it possible to use a running instance of Firefox with
Selenium?

I don't want to use Selenium for testing, I would like to use it to
automate interactions with various websites. I have done some reading
and found webdriver.firefox.useExisting, but can't figure out how to use
it to get the actions I would like. If it is even possible to do what I
want, a short piece of example code to get me going would be appreciated.

Regards, Jim

David

unread,
Nov 4, 2016, 3:08:53 PM11/4/16
to Selenium Users, jf_b...@comcast.net
Why do you need this for an existing instance of FF? If it's just to exploratory test some stuff out and run some automated interaction with manual interaction in the same browser session, you should run Selenium commands with python shell (not python script) and/or start Selenium from script to run some automation first but which breakpoints out later for you to do manual stuff in the session: http://daguar.github.io/2014/06/05/just-dropped-in-interactive-coding-in-ruby-python-javascript/

Jim Byrnes

unread,
Nov 4, 2016, 11:46:04 PM11/4/16
to seleniu...@googlegroups.com
On 11/04/2016 02:08 PM, David wrote:
> Why do you need this for an existing instance of FF? If it's just to
> exploratory test some stuff out and run some automated interaction with
> manual interaction in the same browser session, you should run Selenium
> commands with python shell (not python script) and/or start Selenium from
> script to run some automation first but which breakpoints out later for you
> to do manual stuff in the
> session: http://daguar.github.io/2014/06/05/just-dropped-in-interactive-coding-in-ruby-python-javascript/
>

The whole idea is to get rid of manual interaction. I want to write some
one click logon scripts or or a script to get a site in a state that
makes it easy for me to interact with it. Right now my focus is on
Python so when I learned of Selenium I set out to see if I could make it
do what I wanted. If Selenium needs to open a new Firefox window every
time I run a script it is not the solution I was hoping for.

So can Selenium use an existing instance of Firefox to run my scripts?

For instance can this script be modified to run in an instance of
Firefox already running on my desktop?

# login_yahoo_mail.py

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.Firefox()
driver.get('http://mail.yahoo.com/?.intl=us')
enter_email = driver.find_element_by_id('login-username')
enter_email.clear()
enter_email.send_keys('myemail')
next_button = driver.find_element_by_id('login-signin')
next_button.click()

enter_password =
WebDriverWait(driver,10).until(EC.visibility_of_element_located((By.ID,
'login-passwd'))) #wrapped, should be all on one line

enter_password.send_keys('mypswd')
signin_button = driver.find_element_by_id('login-signin')
signin_button.click()


Regards, Jim

⇜Krishnan Mahadevan⇝

unread,
Nov 4, 2016, 11:48:53 PM11/4/16
to Selenium Users
No. Selenium cannot interact with an already spawned browser instance. Selenium needs to spawn a browser before it can interact with it.

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/



--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/nvjkjq%24o3j%241%40blaine.gmane.org.
For more options, visit https://groups.google.com/d/optout.

Jim Byrnes

unread,
Nov 5, 2016, 12:18:11 AM11/5/16
to seleniu...@googlegroups.com
On 11/04/2016 10:48 PM, ⇜Krishnan Mahadevan⇝ wrote:
> No. Selenium cannot interact with an already spawned browser instance.
> Selenium needs to spawn a browser before it can interact with it.
>
> Thanks & Regards
> Krishnan Mahadevan

Krishnan,

Thank you for the clear answer. That is disappointing. I was hoping to
use Python to write my scripts.

Regards, Jim



Andreas Tolfsen

unread,
Nov 7, 2016, 9:24:02 AM11/7/16
to seleniu...@googlegroups.com, Jim Byrnes
Jim Byrnes <jf_b...@comcast.net> writes:

> Using python is it possible to use a running instance of Firefox with
> Selenium?

I don’t think you can with Selenium, but if you are using geckodriver
you may be interested in the `--connect-existing` flag, which does what
you want.

Note that the Firefox must be running the Marionette server, which you
can enable with the `--marionette` flag to Firefox.
Reply all
Reply to author
Forward
0 new messages