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/")
Related
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.
When a link is clicked manually in my application, it opens in new tab in Chrome and IE.However when my script is run, the link opens in a new window in IE instead of new tab. Same script runs as expected in Chrome.
Has anyone faced this issue?
When a link is clicked, I understand your test script has code to just do
element.click()
which opens the link in new tab.
If yes, its upto the app code to open in a new tab or new window. and if it is working in Chrome and not in IE, its nothing to do with your Selenium Test script.
You got to check with your developer to troubleshoot it. I hope it answers your query.
I am writing a test that verifies that a warning to the user before the user opens a document. If the user says that they still would like to open the document, the document opens in an external application (pdf or word).
But now I have an external application over the browser window, and it messes up for other tests.
So, what are the best practices around this kind of issue? Rewrite of the appliction to allow for not opening documents in test?
Added description:
The problem is twofold.
1) It starts processes (word and acrobat) that fills the desctop and requires resources from the test-slave
2) The external process seems to interfer with other tests since (guessing here) it is located over the browser window.
what i understood from your post is, the document(word/pdf) is opening in the browser window hence you are not able to proceed with further steps. If so, you can verify the Title to make sure the document is opened in browser window and can navigate back using below snippet.
driver.navigate().back();
Hope this helps.
What I understand from the line
'But now I have an external application over the browser window, and it messes up for other tests.'
is that once user clicks on open button a new window opens up (Window based application) since you have mentioned PDF or Word.
You can use robot class in such cases, below code snippet will close the current active window:
Robot rbt = new Robot();
rbt.keyPress(KeyEvent.VK_ALT);
rbt.keyPress(KeyEvent.VK_F4);
rbt.keyRelease(KeyEvent.VK_ALT);
rbt.keyRelease(KeyEvent.VK_F4);
Make sure you deal with sync issues properly so that intended window is closed instead of AUT.
I am facing below described issue while automating the application using selenium webdriver:
When I click on a link a new window should pen with the contents of that window, but when I click on the link new window is opening with login screen, what may be the issue, can anyone help me in this regard.
This issue is only with automation (manual click always works), but sometimes works.
Thanks in advance
Sounds like when a new window opens, all of the session cookies from the previous window are not being transferred. In this situation I would put a try catch block to login again if the login window appears.
How to maintain session in selenium while opening new window. I am clicking a download button after which a file should be asked to download(IE). But running via selenium it opens a new window asking again to login???
I had similar issues. I don't know your implementation, but maybe you're cleaning cache with each new browser Instance. Try to find why it's opening new Window instead of using same browser instance and just open it's download_window. How you handle default_window can also be the answer you are looking for.