Need help troubleshooting button click in Selenium - asp.net

Update:
After further investigation, actually what's happening is when the checkbox is checked using jquery, the next step is to click the button to save. Well, for some unknown reason, the checkbox is unchecking itself.
Here's the jquery to select the checkbox:
string jsStmt = #"
$(function(){
$(':checkbox').filter(function(){
return $(this).parent().next('td').text() === 'Label to look for';
}).prop('checked', true);
});
";
IJavaScriptExecutor js = (IJavaScriptExecutor)_driver;
js.ExecuteScript(jsStmt);
I can see the checkbox get checked, then when the dialog closes I can see it get unchecked?
OP:
Button click event for Selenium testing has been working for a while. All of a sudden, it's not working anymore. Only possible change was some 3rd party css change but I don't know what it could've been.
The button is kind of buried in layers, however, there's a checkbox that gets checked by Selenium that is still working fine, and it's the reason why the button needs to be clicked.
I can debug, and see that Selenium is finding the button. It appears that the button gets clicked but the postback event doesn't occur.
I can stop execution right before the click event and open developer tools and manually type in the statement to click the button, AND that works!
I even tried executing the click with JavaScriptExecutor with no luck.
I am so lost why it's Not firing postback event.

In short, try clicking the checkbox using an IWebElement instead of javascript.
I would suggest avoiding using IJavaScriptExecutor as much as possible in selenium tests as it can lead to performing functions the user wouldn't actually be able to do with simple interactions, or having those functions behave differently than you would expect because the execution path is different than what a user would do if they just clicked something.
I think that's what you're running to in this case where you're trying to mark the box as checked.

Related

Trying to set up a keyboard shortcut of a button inside a webpage and press it multiple times

My work is to watch videos, select some options and then press the "Submit" button. The thing is that the options I have to select are on the left side of the webpage and the "Submit" button is on the right side. I think I will be able to do my work faster if I can make a keyboard shortcut to press the "Submit" button. I somehow built this code
var button1 = document.getElementById("_SSsubmit");
window.addEventListener('keydown', function(e) {
if (e.altKey == true && e.keyCode == 83)
button1.click();
});
I put it in Chrome's Developer Tools Console and it works only 1 time. The next time when I press "Alt + S" - nothing happens. Is there a way I can make it work while the tab is opened?
The event listener itself will trigger multiple times so long as the page isn't reloaded, you can test this by replacing the button1.click() with a simple console.log(). It seems to me that either:
a) the page is being reloaded every time you submit, in which case you would need to paste the code into the console every time the page loads or
b) the submit button element is getting replaced with a new element each time, in which case you would need to re-assign button1 every time. Most likely, the page is being reloaded.
In either case, your best bet here is probably writing a small Chrome extension so that you won't need to keep pasting code into the console.

Click Button in ExtendedSelenium2Library selects button very slow

I am using 'Click Button' from ExtendedSelenium2Library to select Login button on my login page.
But is takes more than 12 seconds to select the Button. With Selenium2library it works immediately.
I prefer using Extendedselenium2 instead of selenium2. How to make it click faster?
TL;DR
Click Button ${button} True
Seems you already figured this out, but I had the same problem and it took some time to figure it out. So this is for future reference.
ExtendedSelenium2Library waits for AngularJs to be ready to process the next request. As can be seen here ExtendedSelenium2Library (and like you already said). So by using these commands that wait for Angular to be ready, when you are not using AngularJS, it is necessary for the timeout to kick in which is about the 12-14 seconds you experienced. To still be able to use the extended library and have "fast clicking" you need to set the argument "skip ready" to "True".
Example:
Click Element xpath=//a[#href="#/motor"]
Becomes
Click Element xpath=//a[#href="#/motor"] True

Window.Open without popup-blocker

i want to open a popup window when user leaves tab or closes browser, the available option with me was window.open, but with that, it asks for popup blocker, if it is not enabled, i tried every possible ways to ignore popup-blocker but in vain, i tried onunload, onbeforeunload, but it does not works, i also tried to use modal dialog, before the tab/browser, i used it in onbeforeunload event, but it shows a browsers alert message, which i dont want, my simple requirement is, i need a popup window (if possible) or modal dialog, on the close of tab/browser, but should ignore popup-blocker, i guess with modal dialog, i dont need to worry about popup-blocker, because that wont be the new window, but how i would be handling it, while user closes tab/browser. If any of the above option is not possible, can anyone help me with any other possible alternative, or helpful articles.
Edited Question
i used the below script and with that i can open a new popup window on link click, without popup-blocker interfering in it
$('a[href=http://www.google.com]').click(function(){
window.open(this.href);
return false;
});
then why its not possible for the closing events.
You can't - because that's what popup blockers do: they block popup windows (i.e. calls to window.open or invocations of target="_blank" links) unless it is directly in response to a user mouse action.
Opening popups when a browser window is closed was a common tactic of "pop-under" ads in the early 2000s, and it irritated users, that's why Firefox and IE6's popup blocker block them, and there is no way around it for you unless you ask the user to disable their popup blocker on your site (and I think you'll find most of them will have no idea how to do that).
What are you trying to accomplish anyway? What is the content of this popup that you want the user to see? What other approaches have you tried?
Exact duplicate of your previous question....
I'll post my answer for it here as well though...
Popup blockers are designed to prevent this behavior.
I would suggest using a modal window instead of an actual browser window. I don't think that these get blocked because they are opened within the page itself.
As for the event... You could do something like...
window.onbeforeunload = function whatever() {
//Do code here for your modal to show up.
}
If you are just trying ot give a warning or something you could do
window.onbeforeunload = function showWarning() {
returnString = 'Whatever you want your message to be....';
return returnString;
}
By returning something in the onbeforeunload statement it will show a confirm box with your message in it.
Popup blocker will not block the opening of popups if the javascript code which opens the popup is executed on user's direct action like click, keypress, drag, etc.

Cannot get click="{ myTabNavigator.selectedIndex=3}" to work

I have a mx:TabNavigator with 5 tabs. As a secondary navigation option for the user there is a "Next" button on each tab that takes the user to the next tab. Each "Next" button uses click="{ myTabNavigator.selectedIndex=x}" set to move to the next tab where x is the tab number. All of them work except for the one on tab 2 which is supposed to take the user to tab 3. Nothing happens.
I can copy this button to tab 0 and it works fine taking the user to tab 3. It just will not work from tab 2.
I have tried moving myTabNavigator.selectedIndex=3; to an event handler and have confirmed that the click event is calling the event handler, but it doesn't work from there either.
I have cleaned the project, restarted Flash Builder and the browser and cleared the cache in the browser. Cannot get it to work.
Any suggestions?
Thanks,
John
I found the problem. I found that the tab 2 itself had click="{EditDetailsTabNavigator.selectedIndex=2}" in it. Took this out and the button works. Guess every time I clicked in the tab it would fire.
Not exactly sure how it got there, but I have found when pasting into a property in Design mode that occasionally the paste goes some place else in addition to where I have the cursor. I think that is how it might have gotten there.

Pop Up Pages to close once Save button is clicked

I have 12 pop up pages on my site with a Save and Cancel button. My requirement is once the Save button is clicked on the pop page i want the server side code to execute and once its done I want the pop up to close.
Is that possible? If yes, kindly let me know how do I achieve that.
You can put a small Javascript on each popup:
<script type="text/javascript">
window.close();
</script>
Once the page has loaded (and all the code is run) this Javascript should close the window. Please note, different browsers will behave differently! Some might close it, some might alert warning, others may block it completely.
As far as I know this is the only way that could close a browser window. Either way, any number of popup windows over 0 is arguably an unfriendly user design. 10+ and you should be seriously reconsidering your user friendliness!
What you can do:
Create update panel and make your Save button as trigger to it, once button is clicked it will execute code behind without closing your popup.
Use your ScriptManager to register statrup method (JavaScript). This method will close your popup
ScriptManager.RegisterStartupScript(this,this.getType(),Guid.NewGuid().ToString(),"/your code to close popup/",true /this true will add script tags to your script so you don't have to write /);
Cheers
Sorry but this SO script wont highlight code, I don't know what is the problem.
At the end of your code the below lines of code will help to close the window.
this.Page.Response.Clear();
this.Page.Response.Write(string.Format(CultureInfo.InvariantCulture,
"window.frameElement.commonModalDialogClose(1, '{0}');", lblText.Text));
this.Page.Response.End();

Resources