I have a disturbing popup that breaks automation test. It is client side validation popup appended to a textfield that only takes number, if I input a text and click the submit button, the popup will suddenly appear and stop the test. How do I overcome this? Appreciate. It is the one having a yellowish bos with exclamation mark, that reads "Please enter a number". When I viewed the source of the page, I found nothing to reference on this popup.
Since you have mentioned it is not a pop up window I think switching the focus to the activeElement should be sufficient.
Driver.SwitchTo().ActiveElement();
The popup appears because the text you put in the input field of "Institution Code" is a letter (o) while it expects a number.
Basically, your script puts the number of the "Institution Code" into the Username field.
Try correcting the Strings that you send.
For negative tests, if you want to get rid of the popup, you need force the input value of the "Institution Code" to be a number and then trigger onBlur() event. This way, the validation would pass.
First, it's good idea to put also your testing code, because I think the main problem will be there. But If you would like to remove this yellow warning popup:
Add to your submit button attribute "formnovalidate"
f.e.:
<input type="submit" value="submit" formnovalidate />
This warning popup is native browser HTML5 validation invoked by submit action.
Reference:
https://www.w3.org/TR/html5/sec-forms.html#element-attrdef-form-novalidate
Related
Background
Here's what I want to happen:
A user is on one page1.html (jsFiddle).
When they click on one of the <a href...> links, I want to navigate to page2.html (jsFiddle) and simulate the user entering the number into the textbox and clicking on the button.
Example: On page1.html, user clicks on display 2. Then we will navigate to page2.html and get an alert of 2 (as if user had entered 2 and clicked the button).
Question
How do I do this?
Is there a way to make a C# method with a specific URL to navigate to, such as page2.html/searchfor/2?
Or is there some way in JavaScript to manually go about doing other things after navigating to <a href="page2.html">?
Things I've tried
Using a <span> with an onclick function, but then it's not a true link like <a href> where I can middle click to open in new tab and right click to follow link
Wrapping my first attempt in <a href> tags, like <span>Display 2</span>. This still doesn't solve the problem of performing extra actions after navigation.
Note
I am building this webpage using Entity Framework, ASP.NET MVC, and C#.
I have simplified the problem for discussion purposes, but the concept is the same.
Try using the page2.html document's onload() function. You can pass parameters through the URL, then take that data and perform "other actions" as soon as the document is loaded.
I used gridview to display some products and used textbox inside a gridview to enter the quantity. I have written a jquery to display an alert box if the textbox is empty. But while displaying alert box the page reloads. But i want to display the alert box without reloading. Since it was in Master page, i dont know how to do it.
may be this will help you
use return false after your alert syntax like this
alert('Please provide value');
return false;
Having a messagebox popup to inform the user that some field does not have a (correct) value is often perceived as annoying to former user as it completely blocks the browser and forces the user to first click "Ok" before she can do anything else.
I didn't find a good reliable source except for this to back up my bold statement:
Error message This notifies the user that an error has occurred, and it usually prevents them from proceeding further in the form.
Emphasize error messages through color (typically red), familiar
iconography (such as a warning sign), prominence (typically at the top
of the form or beside where the error occurred), large font, or a
combination of these.
Success message Use this to notify users that they have reached a
meaningful milestone in the form. If the form is lengthy, a success
message encourages the user to continue filling it out. Like error
messages, success messages should be prominent. But they should not
hinder the user from continuing.
A better way might be to use a non-blocking message and stopping the submit. jQuery Validation is an excellent framework to validate your user input.
I am working with a website that has javascript that does some changes on the page load. However, when I load the page and handle the DocumentCompleted event, this change isn't there. If I then continue paste the DocumentCompleted event, I can see the change happen. However I need this change to happen during DocumentCompleted so I can check some things.
Is there an other event I can subscribe to, or a way to cause the webBrowser to do all the javscript on page?
Edit: This is what I am talking about.
I loaded a sample page just to show you, and clicked the submit button with all fields empty to generate an the error.
Here is the result:
http://s8.postimage.org/zfv6stcar/sfsdfsdfds.jpg
Now if I take the HTML at that precise moment from that WebBrowser control, and render it somewhere else, those errors go away. The same thing happens when the server sends back those errors. If I handle the DocumentCompleted event and take the html, it isnt there. But after the event, it shows up in the control.
Hope you understand, it's hard to explain.
The problem seems to be that the DocumentCompleted event is being fired before the javascript. You should do some reading on how client side/server side things function.
One option is to make a separate method for the DocumentCompleted event and call it form the javascript after it has been completed. This would get the sequencing of these events working properly, but is not very ideal.
Alternatively, you could call the javascript code at the beginning of your DocumentCompleted event. The link below gives a pretty good explanation of how to go about that.
http://forums.asp.net/t/1117189.aspx/1
Personally, I would avoid using javascript and do the validation on the client side .NET, but I don't know enough about the website to really say.
EDIT:
This should be the script you are looking for. Alternatively here is a thread related to your issue. Sorry I don't have the exact code as I don't have a project to test this on.
http://msdn.microsoft.com/en-us/library/system.web.ui.clientscriptmanager.registerstartupscript.aspx
Calling JavaScript Function From CodeBehind
RE-EDIT:
What is happening on the link you provided in the comments, is that each textbox is calling some javascript as well as the submit button. The best way to examine this is using the "Inspect Element" in the right-click menu on Google Chrome. For example, doing this on the textbox would show that it is registered with a few events:
onfocus="$('f_tip_Username').style.display = 'inline'"
onblur="$('f_tip_Username').style.display = 'none'"
onchange="$('f_err_Username').style.display = 'none'"
The first the element with the ID 'f_tip_Username', sets the display style of that element to inline (visible).
The submit button calls the following:
onclick="return o_edit_profile_form.validate()"
Doing a find on "o_edit_profile_form" in the source code, you can find the exact javascript location that is being called. Enjoy!
FINAL EDIT (hopefully?):
Follow these steps: go to your site, right click and go view source. Do a find for "f_tip_Username". This is the ID of one of the div tags being used. The third entry of it, should be a "div tag" that is used under the first textbox to warn of "min 3 characters".
You'll notice above that in the code is a input type "text" with the Name "Username". Notice the three events it has registered in it:
onfocus="$('f_tip_Username').style.display = 'inline'"
onblur="$('f_tip_Username').style.display = 'none'"
onchange="$('f_err_Username').style.display = 'none'"
These either hide or make visible, the div tag we found (f_tip_username) and also a separate div tag (f_err_Username) which is the error message div tag. Let me know if you are not able to find these in the source. Follow the steps I provided and you will find it in the "view source" OR in the DocumentText.
Basically I have an asp.net website with login and search pages.
Currently, I have no idea why, when ever a user hits enter in either of the login text boxes (user name/password) or in the Seach text box, the website is redirected to the default page.
I have no idea why this is happening, I've tried setting defaultButton on both the panel containing the search and the login panel but that doesnt seem to work.
I've also tried catching the key press event with javascript which isnt working either.
I have no idea what event is being fired and why, or why it seems to override everything I try to do.
Anyone seen anything like this before?
---------------Edit-------------------
<div class="searchBar" onkeypress="javascript:return
WebForm_FireDefaultButton(event,'ctl00_MainContent_logView1_LogRepeater_ctl02_lbSearch')">
<input name="ctl00$MainContent$logView1$LogRepeater$ctl02$ctl02" type="text" />
<a id="ctl00_MainContent_logView1_LogRepeater_ctl02_lbSearch" href="javascript:__doPostBack('ctl00$MainContent$logView1$LogRepeater$ctl02$lbSearch','')">
Search</a>
</div>
Ok so here is the code generated by ASP.net that is getting ignored.
---------------Update----------------
I have tried adding a hidden button and setting that button as the defaultbutton of the form and that has stoped it from redirecting to the default page each time but this does mean that pressing enter in a text box just reloads the page, which is better but still isnt Ideal.
This may not be an ASP.NET quirk as much as it is a web-browser quirk.
When you press enter in a single-line text field, the browser will submit the form to the action specified in the form tag.
ASP.NET "helpfully" creates a form tag just inside the body tag and puts all body elements inside it...
As far as I know, you can safely remove this form tag; the HTML specification allows fields outside of form tags for use in JavaScript/AJAX operations.
I have seen this behaviour before, it occurred when the first button on the form was the LoginControl. Everytime enter was pressed it would fire the click event for the login and essentially log the user out. Are you using the LoginControl?
In the end I had to add a hidden button before the login control. The hidden button didn't do anything but it prevented the LoginControl from executing.
I had this same problem once. We had a login form that worked fine when a user hit enter. Then at one point we added a search box/button in the menu bar at the top of the page. Suddenly when users would hit enter they would attempt to perform a search. I resolved it by setting the .DefaultButton of the Form for the page to my login button.
This is my problem, I have one textbox, one button and one label. Everything is inside an updatepanel. Let's say I want to test if a valid html-tag is entered in the textbox when I press the button. In the code-behind I have a method for that.
Everythings works just fine, except when I actually enter a html-tag in my textbox. If I test < html>, it works. But not if I test .
So my question is, doesn't the updatepanel accept html-tags as parameters? Because my breakpoint for the button_click doesn't triggers.
Sorry for my bad english.. :)
Since you're in an UpdatePanel you aren't seeing the real error here...if you just remove the UpdatePanel and do a full postback you will.
Since you're entering an HTML tags, ASP.Net is stopping the postback because you're hitting Event Validation, which prevents symbols like < and > from being entered to prevent scripts attacks on your site.
See here for troubleshooting this and learn about your options. The short version is that by default you cannot enter HTML tags in the field, more specifically, you can't enter < and >