I am developing an automation tool where one of my requirement is to detect whether the input page contains any js error. I have tried using response but this is not wokring.
Can you please help me out as I am stuck very badly.
You can't check if there is a JavaScript error on the page.
What you can do is on "trappable" errors, you can insert text into a hidden field and read that in your c# code.
But if there is an error in code then I don't think you'll be able to check that in c#.
Actually, you could have a hidden field on the page that already has text in it. Then use JavaScript to clear out the field.
In c# code, if you can see an entry in the field, then there was an error in the JavaScript and if it's empty then the JavaScript ran ok and there was no error.
Do you mean something like described here? Log client side js errors
Related
I am trying to parse a web document. Using HtmlAgilityPack (C#)
That is exactly what looking for href value of a tag.
I'm parsing the http://www.ntis.go.kr/ThRndGateList.do
Although successful parse, the value is slightly different.
I do not know why.
The actual value of the web is as follows:
The value obtained through the Htmlagilitypack are as follows:
As you can see, this strange starting with "jsessionid" value in the href value is obtained. What reason?
Thank you for regards.
It is probably because in your browser (in your case Chrome) you are logged in. If you make the request via HtmlAgilityPack you are like a freshly open browser:
Not logged in
Never on this page before
The Webapplication your trying to use generates a JSESSIONID when someone opens the page for the first time and this id is transfered via the URL.
This question could help you to understand the technology behind the webapplication: Under what conditions is a JSESSIONID created?
I've searched the web for 2 days now and am about to give up on this, but I'm soo close to the final solution... so you're my last hope. ;)
I have made a little C# application with Windows Forms GUI that uses a webBrowser element to display an HTML file with a TinyMCE editor embedded - this way I get a nice window with customizable editor functions I can use perfectly for my needs in this project.
I can set the textarea input for this editor window without problems thanks to this solution posted here on stackoverflow: https://stackoverflow.com/a/16322324/3498545
However I'm having big troubles reading text from this textarea. If I read the element by ID as shown (for setting content) in the solution above, I get the old text, as TinyMCE never really saves the changes.
But how do I get the input that my users will make in the textarea via TinyMCE? Is there some way to trigger a form send in HTML to get this input?
Thank you so much for you help!
Ok, to answer my own question (maybe others find this useful sometime later):
The changes of TinyMCE don't get written back to the textarea field in realtime, so I had to work around that. One solution would be to add something in the javascript header that writes every change back to the textarea immediately, however this caused problems for me as TinyMCE code clean up is not involved at this point.
My solution was to temporarily create a new file where the input of the TinyMCE field gets written directly into source code, which is a piece of cake to read back in C#.
The javascript code needed looks like this:
setup : function(editor){
editor.on('submit', function (){
tinymce.triggerSave();
document.writeln("<!DOCTYPE html><html><body><div id='content'>"+document.getElementById('textarea').value+"</div></body></html>")
document.close()
});
}
After that you can read the content in C# with the following code:
webBrowser.Document.GetElementById("content").InnerHtml
Now I can store HTML formatted code in my SQL database that can be managed and edited with a shiny interface. ;)
I'm writing a test for a webapp. At one point in the application the webpage is completed using Javascript.
For testing I'm using Visual Studio 2012 with NUnit and Selenium.
I want to check if the box with id=j_idt13:JNumber has the text value of sometext.
IJavaScriptExecutor js = driver as IJavaScriptExecutor;
string valoare = (string)js.ExecuteScript("return $('#j_idt13\\:JNumber').val();");
Assert.IsTrue(valoare.Equals("sometext"));
I keep getting this error:
"Syntax error, unrecognized expression: unsupported pseudo:JNumber".
What am I missing here?
I know you have something that works but I'd like to caution you to avoid using JavaScript to fetch the value of the element, in fact in general it should be avoided when doing your tests except when there is no other way to do what you want to do. The reason is that Selenium is supposed to behave as a typical user would. Typical users don't type JavaScript into a page or interact with it directly. This goes extra for using jQuery as your tests should not assume that jQuery exists on the page and is functioning. Selenium itself provides the ability to fetch the values of fields so I'd recommend you rewrite your code to something like:
driver.FindElement(By.Id("j_idt13:JNumber")).GetAttribute("value");
After some trial and error I found something that works:
string valoare = (string)js.ExecuteScript("return document.getElementById('j_idt13\\:JNumber').value;");
Why it works, I don't know. Basically is the same command.
And jQuery is working with other commands, just not the one I tried first.
I need some ideas... I have a SQL table that contains error codes, and messages that I will use to display in the web application based on the code column for validation purposes.
If by using server side to do checking, I can load the messages whenever they hit the condition by matching with the error code I put, and display at the menu. But each time a post back needs to be done to show the error code and message, by using the update panel, I can do a partial postback, still I can't style as I want.
If I using client script to check. i can style as I want, but I will need to load the error code and message on each pageload, and chop it 1 by 1, javascript to process and based on code, show the error message, I dont think it is a good idea, is there any better idea to achieve this? I kinda stuck due to my limited knowledge, any idea will be great, thanks
I am new to ASP, and have jumped right in and started a new MVC 4 project.
I am using the standard template and am trying to edit the login page. The problem I am trying to solve is this:
If you open Fiddler and login you can see the user name and password in plain text. What I would like to do would be to use a C# function I have created in a helpers file BEFORE the post is submitted, for example on a button click event, is this possible?
If so can someone point me in the direction of a tutorial/ example please as this has baffled me for a few days now!
Thanks again for your help
Don't reinvent the wheel. Use https instead so that data does not travel as plain text.
You can't run a C# function before the postback, how would you accomplish that? C# code runs server-side, but you post the form from the client-side. You can't apply a C# method on something you haven't shown it yet.
You have basically two options:
1.) use javascript to somehow alter the data before sending it to the server
2.) use SSL to protect the channel
The problem with the first option is, that ANYONE who sees the form can see your javascript code as well. In other words, no matter how strong protection you come up with, the attacker sees the algorithm, so he can decode the data very easily... Probably the most reliable option is the second one - SSL. It isn't 100%, but at least it's much harder to penetrate...
If you want to encrypt the data before the form is submitted you can only rely on client side code - javascript. This is in no way the optimal solution, as already pointed out by others, you should use https.