I have written a small application that needs to log in to a website to perform some actions.
The problem is that whenever I try to set the password field on the website it doesn't accept the password.
I have found a way around this by using the SendKeys function. The problem with that is that it requires focus and the program requires to run in the background.
Is there a way to do this?
Here is an example of how you'd set the Username Field:
WebBrowser.Document.GetElementById("field-username").SetAttribute("value", "UserName")
Any help would be great.
The answer to this question is as follows:
WebBrowser.Document.GetElementById("field-loginFormPassword").SetAttribute("maxLength", "20")
WebBrowser.Document.GetElementById("field-loginFormPassword").SetAttribute("value", "yourpassword")
By changing the "maxlength" value it allows you to set the "value" to the desired text and then you can submit the Form and it will accept it.
Try with mshtml or Html Agility Pack
Related
Hi all I have done some google work and not come up with a great deal apart from using the browser within a From which I dont want to do.
Has anybody some sample code or a good resource that is detailed enough to get me on my way plesae
So for example
Process.Start("https://www.google.com")
and target the search element with a string and click search.
Using the default browser
Please help me...
Doing something like this would work:
string mySearchQuery = "this is a search example";
Process.Start("https://www.google.com/search?q=" + Uri.EscapeDataString(mySearchQuery));
If I'm understanding you correctly, this would use the default browser set in windows, then the query is just passed in as a GET request (that's the ?q variable).
I am just starting to learn Jquery and working on asp.net webform app that will be used on a touchscreen device, and I need to capture user signature, basically user will sign and after hit save, I want their signature to be saved as an image to SQL server database so I can retrieve and display it later on a webpage.
I found this question: Capture Signature using HTML5 and iPad
and the jQuery plugin works great, exactly as I want.
Here the demo: http://szimek.github.io/signature_pad
Here the plug-in: https://github.com/szimek/signature_pad
So on the demo I see after hit "save" you will go to a new tab that display an image of your signed signature, and I noticed that the url is something like
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAApIAAAE+CAYAAAA+vvBuAAAgAElEQVR4Xu3df8i37V0X8I/l0GY5BzZdiWslKhnNUaBR62lBP0htjuiHfz0uROgPmQsH/hE8jiKKjLl/IoLa9k+NMOYyhCRamyM0WI9bUBst5kzbUNfjxBlmaLy389jO+3q......
What does this url mean?
what type of variable will be used to store this in database table (nvarchar, binary...)
3 (MAIN QUESTION). How do I get those data text in code behind C# button click event to store them to a string variable for other purposes. Can someone provide a simple example so i can go from there?
if I am missing something please let me know, as I am looking at the .html file and those .js files in the demo project of that plugin, I am lost.
That URL is in BASE64 format. You can use that long string of characters in the SRC attribute of an image tag and it will be displayed.
To get better performance, the recommended way of storing photos is to store the image on the disk (using some kind of server side language) and then save the name of the file in a database as a CHAR or TEXT.
Not quite sure. I've never used the library before.
That is a Base64 encoded image.
data: says that data is following instead of a URL
image/png; specifies the content "mimetype" the data should be served as
base64, indicates the encoding type of the data
As base64 only uses ASCII characters, a varchar(MAX) would be suitable for storage. No need for nvarchar. I normally store the base64 encoding only (the last part after the comma), and keep the mime-type (e.g. image/png) in a separate field.
There are many options in C#. If you store the base64 part separately, you simplify the code a bit.
Turn it into an image server-side using byte[] imageBytes = System.Convert.FromBase64String(base64data) and creating an image from the byte array and type.
Inject the image into a webpage <img src="#Html.Raw("data:"+ mimetype + "base64," + base64data)"/>
Notes:
As #anthony mentions, your would typically store images as files (or in Blob storage nowadays) and only record the filename/URI. This depends on quantity size & usage.
We have found it convenient, for certain projects requiring extra security, for base64 images to be stored as encoded & encrypted strings in a database.
From comments: To save to, place the string value into a hidden input and update its value. It will then get posted back like any other string. Our own signature plugin just hides the original <input type="text"> it is attached to and puts the value there.
In addition to TrueBlueAussie's answer:
The simplest way to get your string in CodeBehind is:
Declare a HiddenField using ASP and assign a Static ID to it. (Static ID is important since ASP normally assigns automatically generated IDs to each control, and this can get difficult to predict).
Shape your JavaScript function in a way that SignaturePad writes the output base64 image string into this HiddenField. You can for example, use a button "Verify" that calls the Export function of the SignaturePad.
After the string is written into the HiddenField, read it back on CodeBehind. For this, you can use an additional button, for example something like "Save".
There are of course other options which are much more secure/versatile/appropriate, but this might be a good starting point for you.
so this is my problem.
I use a prepaid account.
I call *100#, and get response from my phone operator about my account balance.
response link
This says "You have 1.12 BAM left on you account and you can use it until 02.08.2014.
Here is the question.
I want to make this cal programmatically, from code.
I know it's easy, using PhoneCallTask.
Is there any way to parse this response???
No, there is no way to parse the response and no way to make the call programmatically (PhoneCallTask just shows the UI with the number filled in and the user has to confirm it)
I'm struggling on logic here - can i get some ideas please! :)
basically i have a c# MVC3 application that accepts a huge amount of text (100+ text areas), modifies it, and then outputs it.
i want to check the length of the combined text boxes and have the process fail validation if they are over X length.
the only solution i can think of is by combining all the text into a string server side and get the length. I'm expecting my competitors to fully abuse the system and attempt to overload my servers when i go live, so i want to try and validate on the client side too if possible.
can anyone think of an efficient way to do this (client or server-side if you have a nice idea).
You could use maxlength css property or you could decorate your model with [StringLength] data annotation to check length of the string
Build a custom validator using a technique similar to this answer by Daron Dimitrov. That will do the check on both client and server side and you can use a ViewModel to decorate the attribute to apply to all of the inputs.
I am using internet explorer to print a html document like this in C#:
ExecWB(SHDocVw.OLECMDID.OLECMDID_PRINT,
SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_PROMPTUSER,
2, null);
This works fine, but I would like to know if the used pressed print in the dialog or cancel.
Is it possble to get this information without a ugly window hook hack ? something like a certain out parameter ?
This is not possible. I had this problem and ended up testing all possible values for the last output parameter, the output parameter is not used for this command.