0

I'm using Splinter to test Webpages. Is there a way to easily open a Link in a new Tab (something like link.middle_click())?

Jace Browning
  • 11,699
  • 10
  • 66
  • 90
testiii123
  • 11
  • 3

3 Answers3

1

Here's a link to a procedure to work around the problem with selenium:
https://gist.github.com/lrhache/7686903

For what I can find this can not "easily" done. I'll refer you the following questions which states some workarounds but there's no easy solution.
- WebDriver open new tab
- How to open a new window or tab in webdriver (Python)?

Community
  • 1
  • 1
1

This opens a new tab

from selenium import webdriver

browser.driver.execute_script("window.open('');")

Then you can switch between tabe and do what you want using:

http://splinter.readthedocs.io/en/latest/browser.html#managing-windows

Delgan
  • 18,571
  • 11
  • 90
  • 141
Axle Max
  • 785
  • 1
  • 14
  • 23
0

HTML and Python/Splinter Combination

First, create a html file with links you want to open in new tabs (e.g. links.html).

<!DOCTYPE html>
<html>
<body>
<h2>Links</h2>
<a target="_blank" rel="noopener noreferrer" href="https://www.google.com">google</a>
<a target="_blank" rel="noopener noreferrer" href="https://www.youtube.com">youtube</a>
<a target="_blank" rel="noopener noreferrer" ref="https://www.facebook.com">facebook</a>
</body>
</html>

Second, open the previous html file, and call the links by python/splinter.

from splinter import Browser
browser = Browser('chrome')
browser.driver.maximize_window()
browser.visit('c:\\links.html')
elements = browser.find_by_tag("a")
for element in elements:
    element.click()
    browser.windows.current = browser.windows[0]