1

I know that if I want to know the corresponding IDs of the windows I currently have open, I use the following sentence on Python:

current_windows = driver.window_handles
print(current_windows)

Output (suppose there were 2 windows opened):

['CDwindow-807A80F3D56E82E4A61529E5898AC71C', 'CDwindow-7CEAB7D7E9B701F6279C4B5C4AEE1A29']

And I also know that if I want to get the title of the current page in the driver, I use the following sentence on Python:

current_window = driver.title
print(current_window)

Output:

Google

However, these windows IDs can't be understood by a mortal like me, so how could improve the sentence above to get the title of those windows?

I mean, to get an output like this that contains all the titles of the current windows open in the driver:

['Google', 'Facebook']
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
NoahVerner
  • 937
  • 2
  • 9
  • 24
  • 1
    I don't think that those hex values can be changed. However, you can always do `driver.title` to get the current window title. By looking at the code `return self.execute(Command.W3C_GET_CURRENT_WINDOW_HANDLE)['value']` it is suppose to return the hex value. – cruisepandey Jan 23 '22 at 10:31

1 Answers1

1

As per the WebDriver Specification of Window Handle:

getwindowhandle

where,

Each browsing context has an associated window handle which uniquely identifies it. This must be a String and must not be "current".

The web window identifier is the string constant "window-fcc6-11e5-b4f8-330a88ab9d7f".

So the output of the following command:

current_windows = driver.window_handles
print(current_windows)

as:

['CDwindow-807A80F3D56E82E4A61529E5898AC71C', 'CDwindow-7CEAB7D7E9B701F6279C4B5C4AEE1A29']

is as per the specification and neither contains the page title information nor can be converted to any human readable format.

To retrieve the page title the only command is:

print(driver.title)
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • I see, so it seems that one viable solution is to iterate over that array of IDs, switching between every single window handle, apply `driver.title` and store the information in an array, for then returning to the first window handle. – NoahVerner Jan 23 '22 at 20:25
  • 1
    yep, but try to keep the code for switching optimized :) – undetected Selenium Jan 23 '22 at 20:26