Opening a link in a new tab
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
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, 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");')
Good idea @rominf
Can I try doing this?
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.
@jsfehler Yeah, I know.
@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 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 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?
@andrewsmedina when i'm putting this method to Windows class then django and flask client have access to this method.
@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 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 how the windows in not implemented in the Django driver, I believe that this expected behaviour for this driver.
Closed by #800