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

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]

Related

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

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

How to open new tabs, switch tabs and close tabs with selenium on chrome after update removed sending shortcuts

There are two parts of switching tabs on chrome (and possibly other drivers too).
You first have to switch the context that the driver is working on, and in my case I also have to change the view so that a certain tab is focused.
You use to be able to just send the short cut keys (ctrl + tab, ctrl + t, etc) to manage switching the views, however that was changed recently.
After causing me a headache for this, and not really finding any good answers to fix this, I came up with some work arounds.
Opening
You use to be able to create tabs on chrome by sending keys the shortcut to the page using the driver. However, it appears that doesn't work any more. Opening tabs in an alternate way is actually fairly easy, by using some Javascript:
((JavascriptExecutor)webdriver).executeScript("window.open();");
You then have to switch the context to the new window you just opened. You do this by using the webdriver.switchTo() method (plenty of documentation on this)
Switching
Another challenge that I faced was switching tabs after the chrome update made it impossible to just use shortcuts. I originally tried using Javascript to give the window a name like:
window.name = 'foo'
And then on a different tab you could do:
window.open('', 'foo')
and it would switch tabs correctly. However the issue with that it would work fine when you are sending it via console, but for whatever reason it would not work when sending it through the JavascriptExecutor.
I found a work around however. It is kind of hacky, but I do not see an alternative as of now. First you want to switch the context to whatever tab you want to be on using the window handles (again plenty of other posts explain how to do this, so I will not go into detail how to get the correct handle) doing this:
webdriver.switchTo().window(windowHandle);
This makes it so now the webdriver is on that tabs context. Then to actually switch the view so that it is synchronized with the context you have to do a bit of a hack. What you do is you open an alert on the context you want to switch views to, and then close the alert. This happens fairly quick so you will not even see the alert open.
((JavascriptExecutor) webdriver()).executeScript("window.alert('Horrible hack to switch tabs')");
webDriver().switchTo().alert().accept();
Closing
Closing is actually very easy. All you do is:
webdriver.close();

Move target out of bounds exception

I am writing tests for a web application and all went well until I had to choose an option from a menu and that option displays a drop down list when hovered or clicked. When I click an option from the drop down list, I get the following error:
MoveTargetOutOfBoundsException: Element cannot be scrolled into view
Does anyone know what this error is about and what I should look for in my code?
Selenium version 2.25.0, java version 1.6.0_31
I've been checking some selenium and google groups regarding this issue in older versions https://groups.google.com/forum/?fromgroups=#!topic/selenium-users/EuZ7a6_lB9Q
http://code.google.com/p/selenium/issues/detail?id=3075
http://code.google.com/p/selenium/issues/detail?id=4102
a more recent discussion
Is it a known issue for Selenium 2.25.0 or is there a way to fix it? I recently upgraded to Firefox 15.0 :|
Note: I found a temporary solution until someone magically fixes this...since I can't find where the problem is...
I run the code before that point where it crashes, I put it to sleep for 10 seconds, I manually click the menu and the option from the drop down list, the window I want is displayed and the code continues with actions from that point. It works for now...I hope this will be fixed since I can't believe that I can run a script in Selenium IDE but I can't run my java code in WebDriver ...this is crazy :|
I guess you are trying to click an element from a dropdown.
You should keep in mind, that Selenium helps you replicate exact human behavior. So if the code fails because the element is not visible, it is probably because the element is not visible.
To make it work, you might want to put a click command on the menu before the failing bit of code.
(to replicate the sleep 10 seconds manually click the menu button method you are using)
Once again, if you can show us your code and also the HTML snippet of the Menu section, we can provide an exact solution.
Maybe you're opening new popup window while opening select box.
This may help you:
WebDriver.FindElement(By.Id("someInputBox")).SendKeys("hello");
(IJavaScriptExecutor)WebDriver).ExecuteScript("document.getElementById('windowOpener_Button').click();");
WebDriver.SwitchTo().Window("newDisplayedWindowPopupName"); // continue to test

Selenium cannot click tab in magento module detail page

I'm trying to validate data using selenium version 1.0.9 in magento grid and its detail page.
First, I walked through Selenium IDE from login page to module detail page and click the tabs available there. Eventually, IDE generates PHP codes so I put the code into proper location.
Note: Here, I have clicked the two tabs so that the events get recorded into selenium IDE.
Then, I run the code from command prompt using following command:
phpunit --configuration /var/www/tests/phpunit_test.xml
I got the error (something like):
ERROR: Element //a[#id='test_tabs_form_section']/span not found.
I modified the code and tried to open the detail page before executing click to above link i.e. "test_tabs_form_section", I am getting same error.
Another strange this is if I verify any text of detail page and remove the code that calls click to module detail tabs, it is works, not sure why?
But I really want to open detail page and click to tab, get forms element values using xpath and validate the data.
Can somebody help me, please?
Any help or suggestion is highly appreciable!
Looking forward to hear from stackoverflow geeks!
Thanks
In case this helps anybody:
I found out more things work if firebug is active. This actually makes sense cause firebug will show the final DOM tree in all it's debugging screens, so it's possible selenium is now able to reconstruct the element path because firebug altered the internal DOM.
If something doesn't work with the default element selection created by Selenium IDE, try switching it over to xpath:id-relative. You're already using that in your question, so maybe you there's an even better selector or you will need to resort to using clickAt instead of click.

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...