Selenium window_handles is not correct when opening a new window with Python

I want to use selenium with Python to open multiple tabs in the same browser and scramble real-time bets in parallel with multiple tabs.

The website home page generates a list of games. However, there is no way to get a link to the game if you do not find the game element and do not use click () (ajax heavy website), which open the game on the same tab. My decision to open several tabs is to get a list of games, and then manually open a new tab with the first homepage loaded, and then click on a game with a different index in the list. However, I believe that an array driver.window_handlesalways includes only one element, which is the current tab, and not all tabs opened manually in the browser.

Can someone tell me what will go wrong, or if you can give a better solution to this problem?

The problem is simplified because the following code:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

# create a new Firefox session


driver_temp = webdriver.Firefox()
driver_temp.implicitly_wait(30)
driver_temp.get("https://www.google.com")
body = driver_temp.find_element_by_tag_name('body')

# manually open second tab
body.send_keys(Keys.CONTROL + 't')
driver_temp.get("https://www.google.com")
body = driver_temp.find_element_by_tag_name('body')

# manually open third tab
body.send_keys(Keys.CONTROL + 't')
driver_temp.get("https://www.google.com")
body = driver_temp.find_element_by_tag_name('body')

#print the number of window_handles
print len(driver_temp.window_handles)

I opened 3 tabs, however len (driver_temp.window_handles) is always 1

+4
1

Selenium API . , , CTRL/COMMAND+T "", .

. :

.


, , , Firefox Chrome - Chrome, , , switch_to.window().

+4

All Articles