title: How to open a link in a new tab with python and selenium
body: <p>I want to open links that I find on a website in a new tab. I have tried to open a new tab and pass the url of the link to the driver as suggested <a href="https://stackoverflow.com/questions/28431765/open-web-in-new-tab-selenium-python">here</a>, however, the new tab simply will not open. (There are a couple of other suggestion for how to open a new tab, but none of them seem to work for me.)</p>
  
  <p>So my latest attempt was to right-click the link and press "t" to open the link in a new tab, like so:</p>
  
  <pre class="lang-py prettyprint-override"><code>from selenium import webdriver
  from selenium.webdriver.common.keys import Keys
  from selenium.webdriver.common.action_chains import ActionChains
  
  # Using Firefox to access web
  driver = webdriver.Firefox()
  
  # Open the website
  driver.get('https://registers.esma.europa.eu/publication/searchRegister?core=esma_registers_firds')
  
  # search for information
  elem = driver.find_element_by_id('keywordField')
  elem.clear()
  elem.send_keys('XS1114155283')
  
  button = driver.find_element_by_id('searchSolrButton')
  button.click()
  
  table_body = driver.find_element_by_xpath("//table[@id='T01']/tbody")
  for link in table_body.find_elements_by_tag_name('a'):
  
      act = ActionChains(driver)
      act.context_click(link)
      act.send_keys("t")
      act.perform()
  
      # ... do something in the new tab, close tab, and open next link ...
  </code></pre>
  
  <p>However, I get an error message on <code>act.perform()</code> which reads</p>
  
  <pre><code>MoveTargetOutOfBoundsException: (974, 695) is out of bounds of viewport width (1366) and height (654)
  </code></pre>
  
  <p>I managed a work around by opening the link in a new window, but I would really prefer the tab-version, as it would take longer to open a new browser window rather than a new tab.</p>