4

For a user already using Firefox (or any other) is there a way to connect to that browser using selenium?

Conditions:

  • the browser icon was clicked on by the user.
  • i do not want a new window to pop up (when using selenium).

Example: a user wishes to log into Facebook and wants a program to enter his lengthy password (i can do this with the webdriver etc...).

Is there a way to connect (to an already opened browser) and send commands to that browser?

George Pamfilis
  • 1,397
  • 2
  • 19
  • 37

1 Answers1

1

You just want to use switch function. You can switch to new browser by driver.switch_to.window(driver.window_handles[1]) then you can drive it. If you want to switch back to first window driver.switch_to.window(driver.window_handles[0]).

>>> driver.window_handles
[u'{7355ca99-910b-554d-8478-f8a550e0c767}']
>>> driver.execute_script("window.open('');")
>>> driver.window_handles
[u'{7355ca99-910b-554d-8478-f8a550e0c767}', u'{5a0824a9-9d55-0841-87b8-35a26d4a8b83}']
>>> driver.switch_to.window(driver.window_handles[1])
>>> driver.find_element_by_css_selector("#email").send_keys("dfjd@ak.com")
>>> driver.switch_to.window(driver.window_handles[0])
>>> # write your case to parent window
Mesut GUNES
  • 7,089
  • 2
  • 32
  • 49