0
from selenium import webdriver
from selenium.webdriver import ActionChains

driver = webdriver.Firefox()
driver.get("https://www.google.com")

# open a link in a new window
actions = ActionChains(driver)
about = driver.find_element_by_link_text('About')
actions.context_click(about).send_keys('t').perform()
print(driver.current_url)
driver.switch_to_window(driver.window_handles[-1])
print(len(driver.window_handles))
print(driver.current_url)

I tried to open a link in new tab by right clicking a link and selecting open as new tab but on inspecting the length of window_handles it is only one.So how I could I go to "About" page and why length of browser.handles=1?why not 2?

Nimish Bansal
  • 1,719
  • 4
  • 20
  • 37
  • See this: [Opening new tabs in Firefox](https://stackoverflow.com/questions/28431765/open-web-in-new-tab-selenium-python) – SajidSalim Sep 05 '17 at 06:18
  • what if I have to explicitly open by clicking.Whats wrong in my code? – Nimish Bansal Sep 05 '17 at 06:21
  • Check [this answer](https://stackoverflow.com/questions/46015904/open-link-in-a-new-tab-with-python-selenium-chrome-webdriver/46016954#46016954) – Andersson Sep 05 '17 at 06:29
  • It opened a link in new window. but i want to open in new tab (using firefox) .If I manage to open it in new tab then I am not able to switch to that page in selenium since window_handles length remains 1 – Nimish Bansal Sep 05 '17 at 06:37
  • How should I edit to get upvotes and answers.I lost my previlege to ask question and neither I am able to edit it :( – Nimish Bansal Sep 24 '17 at 04:41

0 Answers0