selenium window_handles not correct when new window is opened wtih Python -
i want use selenium python open multi-tabs in 1 browser , scraping real-time betting odds simultaneously multi-tabs.
the website home page generate list of games. however, there no way link of game unless find game element , use click()(the website ajax heavy), open game in same tab. solution open multi-tabs list of game manually open new tab home-page first loaded , click on game different index in list. however, find driver.window_handles
array include 1 item, current tab instead of tabs opened manually in browser.
can tell me goes wrong or if can give better solution issue?
the problem simplified code in following:
from selenium import webdriver selenium.webdriver.common.keys import keys # create 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 number of window_handles print len(driver_temp.window_handles)
i have opened 3 tabs, len(driver_temp.window_handles) 1
selenium not provide api manipulate browser tabs. you've noticed applying ctrl/command+t
"hack" open new tab.
see more at:
- controlling firefox tabs in selenium
- opening new tab in same window session of browser through selenium web driver command?
instead, open new browser windows.
well, fair, important mention behavior quite different in firefox , in chrome - if open new tabs in chrome, selenium see each tab window it's own handle , you'll switch between them using switch_to.window()
easily.
Comments
Post a Comment