How to open mutiple tabs within a browser using Capybara? - ruby

I need to open multiple tabs within a single browser and i need switch over all the tabs.
Give me your suggestions. Thanks in advance.

I'm not so strong in capybara. so, i'm giving solution to switch over between tabs using selenium.
For a instance you clicks a button in a web page and it will open a new page.
The new page may open in a new tab in the same browser window or in a new browser window. That is not controlled by selenium. It will control by the browser which you using.
For a instance take firefox, goto tools->ptions-> tabs-> open new windows in a new tab instead check the option. For example, if you clicks a button it will opens a page only in the new tab of a same browser window. For a sake if you unchecked mean it will open a page in the new browser window. Likewise every browser has its own settings.
Try this code:
new Actions(driver)
.sendKeys(driver.findElement(By.tagName("html")), Keys.CONTROL)
.sendKeys(driver.findElement(By.tagName("html")), Keys.NUMPAD2)
.build().perform();
In above Keys.NUMPAD2 refers that you are gonna move to the second tab in the session.
You can move to Third, Fourth, etc... by giving NUMPAD3, NUMPAD4, etc... respectively. Here i am using windows OS, if you are in some other OS use their shortcuts.
I hope this will help you.

You can use this exact function in Ruby:
page.driver.browser.switch_to.window(page.driver.browser.window_handles.last)

Related

Open a new Firefox tab without focusing the browser window

I know that I can open a tab in Firefox from another program, for example using the following command:
firefox -new-tab https://stackoverflow.com/
When running this command, however, the Firefox window will get the focus (at least on Fedora 21 with Gnome 3). This is really annoying: My use case is that I browse through the headlines in my feed reader, which is a standalone program, and hit "open in browser" (which executes a configurable command, see above) on every article I'd like to read, before reading even one. This is necessary for example when I want to open tabs while I'm online but read them later while commuting or traveling.
Thus, my question boils down to the following:
Is there any way I can open a link in Firefox without needing to hit Alt+Tab every time to switch back from Firefox to the program I opened the tab with?

I need to save a CSV file using selenium and Ruby

I'm struggling with a feature.
I have a scenario where I click a hyperlink to download a CSV. I have the command to open the csv file sorted. Once that hyperlink is pressed, a pop up box shows up in Firefox and I need to select the Save File option then press OK.
I have no idea how to tell selenium to do this. I have a test code to confirm a new webpage has opened (below)
new_window=page.driver.browser.window_handles.last
page.within_window new_window do
current_url.should eql "https://...."
end
This approach doesn't work for the download pop up. I need to move to the pop up and press those two options.
Any help would be appreciated
You are missing one important thing: Once your hyperlink is pressed, Firefox directs the underlying operating system to launch a pop up. In other words, you are no longer dealing with Firefox, and therefore Selenium is completely blind to that modal window. Generally the solution is something like Sikuli, Robot, or some other framework.
Also, have a read through this: http://ardesco.lazerycode.com/index.php/2012/07/how-to-download-files-with-selenium-and-why-you-shouldnt/

AutoIt - Internet Explorer Navigate to another page (Pop Dialogue Box)

I am using AutoIT within Internet Explorer to navigate from one web page to another
The code I am using is:
_IENavigate($oIE, "http://www.google.co.uk")
However the web page that it is coming from displays a JavaScript popup box. I would like to click the OK button to allow the Navigation to proceed
I have tried using the following code:
ControlClick("Windows Internet Explorer", "", "[CLASS:Button; TEXT:OK; Instance:1;]")
However this doesn't work due to the fact that when the dialogue box appears the AutoIT process seems to pause itself.
The title on the dialogue box is "Windows Internet Explorer" and there are two buttons. The button I would like to click has the text of "OK"
Has anyone else come across this before? If so how can I solve this problem?
_IENavigate by default waits until the page is fully loaded. The dialog box may prevent a page to be fully loaded. The correct solution would be to:
_IENavigate the page without waiting for the page to fully load
Wait until the dialog box appears and close it
Wait for the page to fully load
The parameters for _IENavigate are like this, and you need to set $f_wait to 0:
_IENavigate(ByRef $o_object, $s_url [, $f_wait = 1])
To wait for the dialog box to appear, you will probably simply repeatedly attempt to click it until the ControlClick function returns it did so successfully.

Open link in same browser tab

How do I open a link in the same browser tab? I tried this code:
ShellExecute(Handle, 'open', 'http://site.com', '_self', nil, SW_SHOWNORMAL);
But it continues to open the link in a new table.
Thanks.
I've written on this topic before:
ShellExecute has absolutely no notion of "tab." In fact, it doesn't
even have a notion of "default browser." All it does is find whatever
program is configured for file names that start with "http://" and
execute the configured command line.
What the browser does with the new command line is its own choice.
The API function has no control. Sometimes, the browser allows the
user to configure it.
Opening a new tab or window is the safest thing to do. Neither you
nor the browser knows whether the user is still using the previous
tab or window.
A possible entry point is using OLE Automation. Using this technique you can connect with any existing instance of MSIE, so that you can bring the current browsing window to a new url.

Selenium-IDE test can't switch browser windows

I'm writing a Selenium IDE script to test part of our website that opens a window that takes the user to a third party site that we integrate with. The test clicks a link on our website, that opens a new window on the third party site where we need to tick a checkbox and submit a form, at which point the window closes and we then need to check another page on our own website.
Our problem is that the script breaks at the Selenium selectWindow action, because it says that it cannot find a window with the given name. If we then manually run that line in the IDE, it works!
I have added numerous waits, pauses and other tricks to make sure that the window exists and has the correct title when the SelectWindow action is hit, but we still get the above error.
The script is...
click link=activate
waitForPageToLoad
selectWindow Third party activation site
Are there any tricks to getting this to work?
You dont need that waitForPageToLoad as i'm assuming the host page isn't reloading.
You may want to check out the api ( http://release.seleniumhq.org/selenium-remote-control/0.9.2/doc/java/com/thoughtworks/selenium/Selenium.html#selectWindow(java.lang.String) ) entry for the command. This is the java docs, but it the same for selenium IDE.

Resources