getWindowHandles not working properly with latest edge browser version - selenium

I am working on an application which supports only Edge Browser.
The login functionality works as follows -
On the login screen, when username and password values are provided and login button is clicked, a new browser window opens with an active alert pop-up saying Login Successful along with OK button similar to the image below -
Also, when this new window opens, the old browser window goes blank.
When user clicks on this OK button (or hits ENTER button on keyboard), user home page loads on this new browser window itself and the old window remains black throughout the session.
Automation -
To handle this flow in automation, I have used getWindowHandles() method where I get the handle of this newly opened window and accept the alert.
This used to work properly till edge browser version 105.
However, when the edge browser version was upgraded to 107, I started facing the issue where the getWindowHandles() method goes into infinite loop and eventually the test times out.
I also tried to simulate ENTER button hit by using Robot class but it made no difference.
I have tried using the edge-driver version matching with the current browser version 107 but the issue persists.
Can someone please let me know what can be done for this? Is these any known issue with newer edge browser version?
Thanks in advance..!!
This is the code written to handle multiple windows and the test times out at getWindowHandles() method itself.
for(String wh : driver.getWindowHandles()){
driver.switchTo().window(wh);
}

Adding a Wait may be the key to this problem:
WebDriverWait wait = new WebDriverWait(driver,20);
BTW, I've tested in Edge 108 (also with Edge Driver 108). There's no such error message and everything works great. You can upgrade to 108 and see whether this issue has been fixed.

Related

driver.switchTo().Alerts() in selenium webdriver using java NOT working in IE11 when executed in perfecto

I will let you know the exact scenario of the issue that I am facing right now while working on IE 11 browser in Win 10 using Perfecto.
Scenario: A webpage has a frame and that frame inturn has a table consisting of lot of data. One such data happens to be a "Delete" link and upon clicking it, I get a pop up of "Are you sure?" with Yes or No buttons.
driver.switchTo().frame(frameID);
Challenge: driver.switchTo().Alert() is not working in Windows 10 - IE11 browser in Perfecto where as it works in CHrome browser of same OS combinations:
Solutions Tried:
1)
((JavaScriptExecutor)driver).executeScript("window.confirm=function(){return true;}");
and many such trail and error methods in javaScriptExecutor.
Error faced: Since "driver" instance is inside Frame, when we execute window.confirm or window.alert, I am facing NullPointerException.
2) Using Robot class for blind ENTER key.
Robot rb = new Robot();
rb.delay(2000);
rb.pressKey(KeyEvent.VK_ENTER);
rb.releaseKey(KeyEvent.VK_ENTER);
Error Faced: Doesn't work. Pop up stays right there.
3) driver.switchTo().defaultContent()
Error faced - closes the pop up and control goes to the webpage without deleting the record which is not the functionality.
4) driver.switchTo().ActiveElement()
Error faced: throws WebDriverException.
Please help in providing a solution.enter image description here
NOTE: Same piece of code works in chrome browser. Issue is with IE11 when run in Perfecto.

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]

screen resolution in mode "Run whether user is logged on or not", in windows task scheduler

I am using Python 2.7 and Selenium 2.39.0. to test a web application. When I run my test as a Windows (7 Ent.) scheduled task with the option "Run whether user is logged on or not", it looks like the screen resolution or window sizing changes; Some buttons become hidden behind the toolbar at the bottom of the browser window and therefore, it can't be clicked by Selenium.
I don't have this problem if I choose the option "Run only when user is logged on"; even if the screen is locked, the buttons are visible and clickable.
According to the Windows task properties, it is using the same user account.
Is there a way, browser setting or a registry key which can help to keep the same resolution and size in both modes?
I know I can scroll down the page, but I am trying to understand and may be prevent this difference of behavior between these two modes.
I've had the same problem. I tried all registry keys I could find, disabled TMM, but to no avail.
Running Selenium with a user logged in seems the only way Windows 7 will give you another resolution than 1024x768. So I ended up setting my Selenium virtual machine like that: have a user log in automatically on startup and launch the Selenium node after that.
In you selenium test, you can call driver.manage().window().setSize(new Dimension(1920, 1080));
Even if you screen resoltuion is 1024/768 you browser will have the correct window size and you buttons will display just fine.
You can also run your window task with user "SYSTEM". So you don't need to worry about opening the user session.
In case anyone comes to this post still looking for the answer as I did.
If you set up the ChromeDriver to run in headless mode using options you can force it to a resolution you want whether the user is logged in or not.
See below which was originally posted by #bunkerdrive in answer to this question:
What is the default window size when running Selenium tests over Azure Pipelines?
Code is C# but I imagine there is a python equivalent to add the options.
var options = new ChromeOptions();
options.AddArguments(new List<string>()
{
"--headless",
"--disable-gpu",
"--no-first-run",
"--no-default-browser-check",
"--ignore-certificate-errors",
"--no-sandbox",
"--window-size=1920,1080",
"--start-maximized",
"--disable-dev-shm-usage",
});
driver = new ChromeDriver(options);

Capturing a newly opened window with Selenium

I'm using the Selenium Client drivers to run tests built in C#. I'm having a problem where the test navigates to a page and clicks on a button in a form with its target set to _blank causing it to open a new window. However the new page being opened returns an XML document and not a typical webpage. Selenium seems to have trouble with this because it hangs when the button is click and the new window opens. No instructions after the click method are executed. The test eventually fails with the error Timed out running command.
Any help/guidance would be appreciated. I've scoured the net but haven't seen anyone running into this particular issue of the page being opened not being a typical webpage which I think is the core of the problem as Selenium can't really manipulate this new opened window. I would post code except that literally all I'm doing is calling the click method on a button which causes a new window to open. Thanks in advance.
To tackle the issue of opening in new window. I typically get url of the link which is to be opened and instead of using selenium.click(), I use:
selenium.open("http://yourwebsite/yourlink")
This helps me to be on the same window only(which avoids opening new window or tab) and when the testing is finished on this page and you want to switch back to original page you can again use:
selenium.open("http://whatever/")

Selenium Web Driver - login event not launching

I'm using Selenium Web driver for testing, but can't ecen get past login page. The code I'm using:
driver.Navigate().GoToUrl(baseURL + "URL");
driver.FindElement(By.Id("loginForm:username")).SendKeys("uName");
driver.FindElement(By.Id("loginForm:password")).SendKeys("pass");
driver.FindElement(By.Id("loginForm:login")).Click();
Element locators are correct and login click is happening, but after that I am not logged in, but page is just stuck there - no error or something. Same code worked in IDE.
I'm using IE9 and also there is changed settings:
var options = new InternetExplorerOptions();
options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
driver = new InternetExplorerDriver(options);
Any advices how to overcome this problem?
This happens with me very often, but not sure if it is the same reason for you.
When you run the tests locally, all the actions (sendkeys, click etc) take place really quickly. The loginForm:login button could be kept disabled until the user enters text in fields loginForm:username and loginForm:password. So there is a possibility that the button loginForm:login could have not been active when it is being clicked.
So I would recommend using an explicit wait to check if the element id loginForm:login is displayed before clicking it.
This step is basically useless but all it does is simply waste some time between "sending keys" to the password text box field and clicking submit.
Also for a quick check you could also do something similar to sleep 2 (make the script sleep for 2 seconds) after entering the password and before clicking the login button.
IF you eventually plan to run this on a remote machine, you dont need to do any of the above two steps, the time delay due to communication between the machines will be sufficient for the whole process to work smoothly.
(The same problem occurs on the linkedin login page- Login button is disabled unless Username and password is entered, but the speed at which the webdriver performs each step, The login button is not active when being clicked on.)