Is there any way to change focus of browser tabs in robot? - selenium

I am using robot framework+python+selenium to create an automation framework.
I am stuck at this point.
On this website. When the link 'a' is clicked, a new tab is opened. On this new new I want to test functionality. My problem is I'm not sure how to change the focus from one tab to another. I tried the switch browser keyword as well as the select window keyword. No luck.

You can make use of the following code change focus of the windows using selenium2Library.
#{windows_num} = List Windows
${nWindows} = Get Length ${windows_num}
${latest_window} = Evaluate ${nWindows}-1
Select Window #{windows_num}[${latest_window}]

Found a simple solution here, that worked for me:
https://www.youtube.com/watch?v=5tVgC-oQVKs

Related

Click not working on combo-box down arrow button karate UI testing

I tried clicking on down arrow button for a Combo Box (Select is not available. Its a React JS application and once I click on arrow button only list shows selection items) using below karate command but click not happened in application and no error displayed. [The same xpath worked in selenium click command,and showing unique item on Inspect search]
And waitFor("//div[#id='root']/div/div[3]/main/div/div[3]/div[2]/div")
And click("//div[#id='root']/div/div[3]/main/div/div[3]/div[2]/div")
Note: Then I tried below command
And assert('//div[#id='root']/div/div[3]/main/div/div[3]/div[2]/div').exists
and got error
javascript evaluation failed: assert('//div[#id='root']/div/div[3]/main/div/div[3]/div[2]/div').exists, :1:19 Expected , but found root
assert('//div[#id='root']/div/div[3]/main/div/div[3]/div[2]/div').exists
It would really help us if you follow this process, it is simple and should not take much time for you to give us a small snippet of static HTML (or you can mix react if really needed).
https://github.com/intuit/karate/tree/master/examples/ui-test
EDIT: you also seem to have mis-matched single and double-quotes in your code.
Also note that you should be able to fire a JS event or click by using the script() API. See this example: https://github.com/intuit/karate/tree/master/karate-core#script
So this is an alternate approach to be able to overcome any tricky situation that comes up.

Robot Framework - Selenium2Library - Chrome & Edge open new tab instead of window

Sorry if this is a mundane question.
My issue is that the user can click on the "Help" button, which by default will open in a new tab, the help page.
When firing the test in Firefox, it creates a new window. Which is great as I can use the Select Window keyword and give it the URL. However, with Chrome and Edge, it just makes a new tab.
I read that Tabs aren't supported - But the weird part is, the test on Edge passes fine, it is just Chrome which is having the problem. Is there a reason behind that?
Is there a way to force it to be a Window and not a Tab? Or something?
I read that I can input a keyboard shortcut of CTRL + Tab. But that feels really dirty and would prefer a better way of doing it.
Error:
ValueError: Unable to locate window with URL 'http://...
EDIT
OK - So instead of using the URL param, I tried the title instead. Just on a whim. And it worked (?) I have no idea how it worked and why using the URL didnt and the title did: Here are the lines I used:
Run Keyword If '${Browser}' == 'Chrome'
... Select Window 1.7.1 User Guide
... ELSE
... Select Window 1.7.1 User Guide - Welcome to the User Guide
Still though, both the "Gets" did not produce a link to the newly created tab / window though :/ - Many thanks to shicky and Helio!
Are tabs not handled largely the same as windows? You should be able to identify what is on the screen as #Helio says by using one of the following:
Get Window Identifiers
Get Window Names
Here are some similar questions that should help you get started, post back here with some further detail if you need more help.
How to get the current URL in Robot framework?
How to make chrome display on the top opened in selenium [Mac OS X]

Switch between different tabs using capybara or selenium

I wish to switch between browser tabs for a feature I am testing. However I have not been able to do this. Have tried using the following:
page.driver.browser.switch_to.window(page.driver.browser.window_handles.first)
The idea been that when I am on the second tab the above code should bring it back to the first tab. However this is not working.
I also just tried to close the second tab using this:
page.execute_script "window.close();"
but this does do anything, the tab is not closed nor is the overall browser window so appears that it is not doing anything.
Had anybody else had problems like this and how did you figure out a solution? I am using FireFox.
Here's my method for closing new tabs.
def close_new_tabs
window = page.driver.browser.window_handles
if window.size > 1
page.driver.browser.switch_to.window(window.last)
page.driver.browser.close
page.driver.browser.switch_to.window(window.first)
end
end
I call this method anytime a new tab may need to be closed.
I was able to switch between tabs using the following
browser.switch_to.window browser.window_handles.last

How to switch between the list of tests and the output/console inside the run window using the keyboard?

When I run tests and open the run window using the Alt+4 shortcut, I find the cursor either in the list of tests on the left or in the console/output on the right.I would like to switch back and forth between the two using the keyboard only.
I have searched in the keymap, the online help and have posted in the RubyMine forum but could not find an answer.
Experimenting with Alt/Ctrl/Shift+Arrows/Tabs/Numbers combos did not help.
The window parts are not individually selectable in the window switcher (Ctrl+E).
I am using RubyMine 5.4.3.2.1
Thank you.
As far as I can see, using Intellij 13.0.1, or a derived IDE, like RubyMine 6 Tab should work, with certain nuances.
When the focus is on the list of tests initially, I am able to tab between the list of tests and the console - the thing is, I cant see a cursor when I tab to the console/output, but if I use shift-up/down to I can see that the console definitely has the focus.
Pressing Tab again puts focus back to the list of tests on the left.
If the focus is in the console/output initially, pressing Tab has no effect and I have to use the mouse to 'escape'.
Earlier versions, based on ItelliJ 12 seem not to support this feature.
I hope this helps.

Unable to find popup window

I am having an issue with finding a popup window in some selenium test code. I am looking at the screen on the test runner and there are two IE windows, one of them is the popup and one of them the page which generated the popup. However selecting that window with
SelectWindow("name=SomeName")
fails. Putting a break point in there and running some diagnostics shows that
GetAllWindowNames()
returns only one window. Very odd. I have duplicated the problem in IE, chrome and firefox so I don't think it is browser specific. I am using C# to drive my tests. Any idea how I might solve this issue?
Edit:
I looked a bit more at how this page actually creates its popup by reloading itself with window.open added to its code. It is rather an odd way to open a popup but I don't see any reason why it isn't valid.
Is there title or some other attribute in popup window's source code? You can locate that using any info you find there. Try to record open popup window in Se IDE and click on something in that popup window. Usually this trick works.
IIRC, there are some situations where SElenium fails to register the window. In this case you can register the window anyway by using the openWindow(ยดยด, ). I think this is described in the explanation of openWindow in Selenijum IDE...