splinter icon indicating copy to clipboard operation
splinter copied to clipboard

Opening a link in a new tab

Open begueradj opened this issue 10 years ago • 14 comments

Howdy,

With Selenium, it is easy to open a link in a new tab. Is this even possible with Splinter? I dived deeply into Splinter API documentation but I did not find anything related to tab features.

Thank you in advance for any hints, Bill BEGUERADJ

begueradj avatar Mar 20 '16 10:03 begueradj

You can do it in the same way that it is done in selenium. Something like:

# from selenium.webdriver.common.keys import Keys
element.fill(Keys.CONTROL + Keys.RETURN)

andrewsmedina avatar Mar 09 '18 01:03 andrewsmedina

@andrewsmedina, I don't like this approach. It's not portable: on OS X you have to use Cmd instead of Ctrl. Also, it's implementation dependent - your solution works only if the element was extracted from the browser, powered by Selenium.

I propose to add a method to WebDriver:

browser.windows.new('https://google.com')

This command can execute following command:

browser.execute_script('window.open("https://google.com");')

rominf avatar Nov 13 '18 05:11 rominf

Good idea @rominf

andrewsmedina avatar Nov 13 '18 18:11 andrewsmedina

Can I try doing this?

szafran98 avatar Sep 04 '20 18:09 szafran98

I think new_tab makes more sense than new, which is too close to __new__ but too different in behaviour for my liking.

@szafran98 Go for it. Just make sure to add unit tests.

javascript-error avatar Sep 04 '20 19:09 javascript-error

@jsfehler Yeah, I know.

szafran98 avatar Sep 04 '20 19:09 szafran98

@jsfehler Am I right that the topic of the issue is a possibility to open link in a new tab not a window? If yes then I almost done it and wrote tests, but I think there is a problem. I'm not using Firefox daily and I recognized that it always open link in a new window. Do you know any way to edit config immediately after run or need i to find workaround?

szafran98 avatar Sep 05 '20 18:09 szafran98

@szafran98 and @jsfehler I believe that his method should belong to the windows scope. My proposal is to usebrowser.windows.visit or browser.windows.new. What do you think about it?

andrewsmedina avatar Sep 07 '20 23:09 andrewsmedina

@andrewsmedina I can move it, but as i see in the docs browser.windows -> """ A class representing all open browser windows """ so how the program will know in which window it should open a new tab?

szafran98 avatar Sep 08 '20 12:09 szafran98

@andrewsmedina when i'm putting this method to Windows class then django and flask client have access to this method.

szafran98 avatar Sep 08 '20 18:09 szafran98

@szafran98 you can put the method in the Windows class inside the webdriver module: https://github.com/cobrateam/splinter/blob/master/splinter/driver/webdriver/init.py#L70

andrewsmedina avatar Sep 08 '20 21:09 andrewsmedina

@andrewsmedina but still when user initialize browser = Browser("django") and then if he type browser.windows.current.new_tab('http://google.pl') he will get error

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'DjangoClient' object has no attribute 'windows'

szafran98 avatar Sep 08 '20 21:09 szafran98

@szafran98 how the windows in not implemented in the Django driver, I believe that this expected behaviour for this driver.

andrewsmedina avatar Sep 10 '20 01:09 andrewsmedina

Closed by #800

javascript-error avatar Aug 24 '21 15:08 javascript-error