Reputation: 4943
Selenium for Java and Ruby have methods to get current window handle.
For example, in Java it's pointed here.
In the same time Pythonic version of Selenium has no such method.
Upvotes: 18
Views: 33160
Reputation: 473763
There is current_window_handle
property available on the WebDriver
instance:
driver.current_window_handle
Demo:
>>> from selenium import webdriver
>>>
>>> driver = webdriver.Chrome()
>>> driver.get('https://stackoverflow.com')
>>>
>>> driver.current_window_handle
CDwindow-B22C1E54-977D-4B2A-8048-E9C73999E9C7
To get the name of the window in python but using javascript you can do this in python: ( I looked for this everywhere, but no answer was given for this)
window_title = driver.execute_script("return window.document.title")
window_name = driver.execute_script("return window.name") # e.g. 'win1'
Upvotes: 20