Description
Add methods for handling tabs in CDP Mode
Up until now, CDP Mode hasn't had direct methods for simplifying the control of browser tabs. That's about to change. (One workaround has been to reconnect()
to regular WebDriver to handle situations where tab-control is needed. Another workaround has been to call the async
API indirectly.)
The following methods will be added to CDP Mode:
sb.cdp.switch_to_tab(tab)
sb.cdp.switch_to_newest_tab()
sb.cdp.close_active_tab()
sb.cdp.get_active_tab()
sb.cdp.get_tabs()
To prevent confusion, the following methods will also be added as duplicates (because the regular SB naming scheme uses those):
sb.cdp.switch_to_window(window)
sb.cdp.switch_to_newest_window()
Note that with sb.cdp.switch_to_tab(tab)
, tab
can be either an integer representing the list location from sb.cdp.get_tabs()
, or it can be the actual Tab
object from the list. If the tab
you wish to switch to is the newest opened tab, you can just call sb.cdp.switch_to_newest_tab()
.
Once implemented, it'll be easy to switch tabs if a website opens a new tab after an action is performed.