简体   繁体   中英

Python webdriver connect to already webpage (selenium)

I need to open multiple links in separate tabs or sessions... I already know how to do it, so what i would like to know is if it's possible to connect to an already open webpage instead of open every links every time i run the script. What i used now in Python is:

from selenium import webdriver
driver.get(link)

The purpose would be once i run the first script (to load multiple links), the second should connect to the webpages, refresh them and continue with the code. Is it possible? Anyone know how to do it?

Thanks a lot for the help!!!!

Connecting to the previously opened window is easy:

driver = webdriver.Firefox()
url = driver.command_executor._url 
session_id = driver.session_id  
driver2 = webdriver.Remote(command_executor=url,desired_capabilities={})
driver2.session_id = session_id

#You're all set to do whatever with the previously opened browser
driver2.get("http://www.stackoverflow.com")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM