Reputation: 1487
For a user already using Firefox (or any other) is there a way to connect to that browser using selenium?
Conditions:
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?
Upvotes: 4
Views: 2429
Reputation: 7401
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("[email protected]")
>>> driver.switch_to.window(driver.window_handles[0])
>>> # write your case to parent window
Upvotes: 1