Postback page minimized the browser - Selenium WebDriver - webdriver

I have a web page that have few dropdowns and when the dropdown item changed it refresh the page and reloads.
so now i am writing script against that page and i have noticed that whenever my scripts select the text from the dropdown my browser get minimized.
my questions, is there any setting to make sure my browser is maximized while running the script?
Here is the code that SelectText from the dropdown:
public void SelectText(By locator, string txt)
{
IWebElement element = driver.FindElement(locator);
SelectElement selectelement = new SelectElement(element);
selectelement.SelectByText(txt);
}
I am using
IE 8
Selenium 2 WebDriver
C#

I strongly suspect that the browser is actually being dropped to the bottom of the Z-order, not minimized. That is to say, it's being pushed to the bottom of the stack of open windows on your desktop. If you have other applications running, and they're running maximized, it can appear as though IE has been minimized, but it really isn't. There are certain actions that are known to cause IE to behave this way, but no one has been able to figure out why yet.
Maximizing the IE window won't solve the problem. Nevertheless, you can maximize the IE window using
// WARNING! Untested code written from memory
// without the benefit of an IDE. Not guaranteed
// to be syntactically correct.
driver.Manage().Window.Maximize();

Related

Using window.open equivalent in firefox causes ,NET session variables to go away. Why? How can I fix?

I have an application which runs in Adobe/Apache Flex with a .NET middle tier.
To run reports I need them to run in a separate window so I use;
navigateToURL(url, "_blank");
This works swimmingly in all browsers (IE, Chrome & Edge) except Firefox (FF). The app has been around for quite a while, and I can't imagine that it never worked in FF, but it doesn't with the last couple of releases.
The symptom is that the .NET "Current.Session.SessionID" changes to a new ID for both the original browser window as well as the new browser window. This causes it to lose all session variables, of course.
The problem only seems to manifest itself if I use "POST" to send variables to the popup window. If I use "GET" everything works fine. An added "bonus" is the "Post" parameters being sent to the new window disappear. So my report doesn't run, and the original window "loses its mind since the session ID changes."
As a test I dusted the cobwebs off and created two ASPX pages which did
<form method="post" name="TestForm" action="TestWopen2.aspx" target="_blank">
The problem was not exhibited in that environment on any browser including FF.
This leads me to believe that Adobe Flex (Flash) is mucking things up a bit.

before closing the Application browser should prompt conformation

I have a small requirement..
if the user dint sign off or log off then he try's to close the browser IE clicking on 'X' (top right of IE or Firefox browser ) then i need to ask a conformation message like "Are you sure you want to close ?" ...
I am using Master page in my application and i tried the event : "window.onbeforeunload " in my master page its works fine, shows an alert(conformation) message. but if i press back button on the browser(IE on IE or Firefox) then also its firing(but it should not) is there any way to full fill my requirement ..I hope i had explained u clearly...if not pl z let me know........
what i mean to say is.. if the Session("USerid") is active or if it contains any value ie.
Session("USerid")="XXX"
at that moment if user trys to close the browse(click in 'X'/Close button browser either IE or Firefox ) it should give prompt a message "are u sure do u want to close?"..
Its all about design steps - but the close and the back button is the same, the close the page, so maybe its impossible to have them all together.
To open, close your script you can make a simple trick. Place them inside a literal and open or close it.
<asp:literal run="server" id="txtCloseAlert">
<script>
... you code here ....
</script>
</asp:literal>
and on code behind.
txtCloseAlert.visible = !string.IsNullOrEmpty(Session("USerid"));
I've looked into this recently and there does not appear to be a standard / consistent way to do this cross-browser hence you back-button problem.
On IE at least you get an event object passed as a parameter to the onbeforeunload method that you can use to get the mouse position, but in FireFox you don't and you would need some other way to determine whether a confirmation is required. It is quite posible that you could get the mouse position in some other way as I haven't looked into that. Point is that if your mouse is not on your form you probably want a confirmation.
You can look at this SO question:
Prevent browser from closing in asp.net
Or do an Internet search on 'onbeforeunload prevent browser closing'.
In your case a synchronous ajax call can be made to the server to do the test.
HTH

JS window.close() let IE hang

for reason I won't bore you with, I'm writing an asp.net application that must open some pages in new browser windows.
I managed to open them within a postback (don't ask why, I just needed to) with this code:
script = String.Format(#"window.open(""{0}"", ""{1}"");", url, target);
ScriptManager.RegisterStartupScript(page, typeof(Page), "Redirect", script, true);
Now I have new windows each one with a button that should close it. I have simply an onclick="window.close()" (but that prompts me when I'm closing the browser) or window.open('','_self','');window.close() (horrible, I agree but it's the only way I found to avoid the JS prompt)
On firefox it works perfectly but on IE7 (the browser our customers have) after 2-3 times I use that button to close the window I can't open other windows (in both cases, with or without the JS prompt). With the method above it does nothing, and with a click me a new window is opened but hangs on loading (it doesn't even calls the Page_Load).
What could be the cause? How can I solve this?
Thank you.
EDIT:
I forgot to mention that I'm using MS Ajax in most of the pages, and that may be the reason that forces me to use window.open('','_self',''); before window.close()
I don't know if this could cause also the hanging of IE
EDIT: Ignore that, it does still prompt the user - sorry!
For your first issue about closing the window, have you tried:
self.close();
Not too sure about the hanging issue though, I use window.open() and have never experienced issues in IE7.
I finally came to a solution:
on the attribute assignment there was a return false; missing.
Now it works perfectly with "window.open('','_self','');window.close();return false;".

Slow javascript with IE8

I'm developing a grid with excel-like functionality using the telerik controls. For example users can click on a cell and the cell turns into an input control for editing. Users can tab to move onto the next cell or use arrow keys for up/down to get the cell above or below. I've found the standard telerik grid is good but I've had to extend it with custom javascript to achieve what I need.
My problem is performance in the IE browser. While Firefox, Chrome, Safari are all fine, IE is a real pain. IE8 is considerably better than IE7 however moving around with the cursor keys is a bit unnatural, and nothing like as smooth as Chrome or FF.
I can't really post sample code due to the complexity of what the grid is doing, but generally I'm displaying the standard telerik grid and using the telerik javascript API to fill and bind in the browser. When a cell is clicked a javascript function moves a previously hidden input control into the cell from a hidden collection and gives it focus. When you tab away the cell value is cleared and the server is updated using ajax pagemethods and the next cell is selected in a similar manner.
The grid has approx 40 columns and 20 rows, i.e. 800 extra controls are hidden on the page and only activated by clicking a cell or through navigating with the keyboard. I originally had just one hidden control for each column but moving up and down with the cursor keys became problematic in IE.
Any advice for things to check that might speed up IE8 would be greatly appreciated.
//selects a cell and sets the value
this.select = function(value) {
this.moveFromTo(this._hiddenCell, this._gridCell);
this._bIsSelected = true;
this.set_inputValue(value);
this._focus();
}
//clears inner content for a cell
this.removeChildrenFromNode = function(node) {
if (node == undefined || node == null) {
return;
}
var len = node.childNodes.length;
while (node.hasChildNodes()) {
node.removeChild(node.firstChild);
}
}
//move back or forwards between hidden or active cell
this.moveFromTo = function(from, to) {
var currChild = null;
this.removeChildrenFromNode(to);
var i = 0;
if (from.childNodes != null) {
while (i < from.childNodes.length) {
currChild = from.childNodes[i];
if (to != null) to.appendChild(currChild);
i += 1;
}
}
this.removeChildrenFromNode(from);
}
Load up your page in IE8, open the developer toolbar F12 and turn on the profiling:
Profiler (tab) > Start Profiling
Use your grid for a bit as normal, and let IE profile your code.
When done, click Stop Profiling, and verify which function calls are chewing up the memory or taking the most time.
They may be ones that are beyond your control (e.g. in Telerik's code) but if anything you've added is the bottleneck post the function(s) back here on SO to ask for advise on how to optimize.
It sounds as though most if not all of your controls related to the grid are created from within JavaScript?
If so there are a couple of things to keep in mind:
IE hates string concatenation: there are numerous posts about it's poor performance
Ensure your clearing your events when switching controls and not just overwriting them
memory leaks are not your friend
IE hates adding controls as much as you do - so reuse them when possible
IE is faster if the controls are created via HTML (why oh why?)
IE hates it when you add lots of dynamic images and CSS with on-the-fly HTML controls
IE prefers innerHTML to addChild() (seems counter intuitive to string issue above)
etc
etc
There's many more, but with IE you also have to implement almost every single JavaScript performance suggestion you can find:
short variable names
ensure variables are properly scoped (otherwise the runtime will jump up scopes until nothing is left to search)
iterators from frameworks like prototype and jQuery are often slower than traditional for and while loops (VERY VERY sad but quite true)
etc
etc
When a cell is clicked a javascript
function moves a previously hidden
input control into the cell from a
hidden collection and gives it focus.
You have to explain the quote above in more detail. How exactly do you move the previously hidden control into the cell? Check the site below for a benchmark that uses different methods to generate a dynamic table. Moving the control using the W3C DOM methods or table methods could slow down IE while working fine in other browsers.
http://www.quirksmode.org/dom/innerhtml.html
Edit: Try this to check if it's faster(not as a final solution):
this.moveFromTo = function(from, to) {
to.innerHTML = from.innerHTML; }
Here are some useful links
Understanding and Solving Internet Explorer Leak Patterns
IE Sieve, Memory Leak detector for Internet Explorer
JavaScript Profiling
Try Google Frame. It pushes the performance on IE8 ;)
Test you code with jslint.com

Open Default page without Addressbar, Menubar & Statusbar in ASP.NET

How can I open my Default.aspx page without Addressbar, Menubar & Statusbar?
Remember it's the user with an already-opened web browser that chooses to visit your website, effectively Default.aspx page, whether or not the browser is launched by you or a program while testing your website. So a bit of client-side/JavaScript "magic" is needed to modify or fake the desired result based on an already existing browser window...
Using JavaScript, you can launch a new window with those features turned off, and close the old window. For example, IE's window.open(..) args are specified here.
It provides an example
varCustomFeatures = 'titlebar=no, status=no,menubar=no,resizable=yes, scrollbars=no,toolbar=no,location=no,directories=no,left=0,top=0,height=';
window.open(windowURL, '_blank' , varCustomFeatures,true);
Details may vary between browser in which case you will likely need to employ browser detection.
You can't.
However, you can create a popup windows without the bars in Javascript using open method, like this:
open("MyPage.aspx", "MyWindow", "toolbar=no,status=no,menubar=no");

Resources