fill File Input form in VB.net - vb.net

I want to make a session for the form, especially on the file input and this is the HTML
<input class="textBox" id="FileUpload" type="file" name="File1" runat="server">
I'm saving the value using
Session("filetxt") = FileUpload.Value
If (FileUpload.Value <> "") Then
Me.FileUpload.PostedFile.SaveAs(Commonly.DirectoryUpload.FullName & "\upload\" & FileDhnUpload.Value)
End If
then I assign it back using
FileDhnUpload.Value = System.IO.Path.GetFileName(Commonly.DirectoryUpload.FullName & "\upload\" & Filetxt())
but I got an error that said "the value property on htmlinputfile is not settable"
so for example when I input test File.txt to the form below and press Back while saving the value
enter image description here
how can I get this when I'm opening the form again?
enter image description here

Related

WQO agent and LotusScript

I am trying to create a div tag in WQO agent using Lotusscript as below :
In my form it is blank form
Dim session As New NotesSession
Set thisdb = session.CurrentDatabase
Set doccontext = session.DocumentContext
Print | </form> _
<form name ="thisform" _
<form name ="thisform" > _
<div id ="thisform"> _
Please wait while we proces your request ........<img src='./please-wait.gif' width=50 height=50></img> _
</div> _
</form> |
However this outputs nothing, am I doing anythign wrong here ?
Edit :
Basically I wanted to print view html view with button to delete the selected records, but before I want to make sure that please wait is being displayed before it prints HTML view.
As per the help page for WebQueryOpen and WebQuerySave agents, you can't use a print statement in a WQO agent to send HTML to a browser.
A WebQueryOpen event runs the agent before Domino® converts a document
to HTML and sends it to the browser. Domino ignores any output
produced by the agent in this context.
You need to put a field in the appropriate place on the form, mark it as pass-through HTML, and have your WQO agent save the HTML into the item value for that field.

Selenium Web Driver , How to enter text in text in Selenium texbox and hit Enter

Once i login to the main application. I want it to enter state name and hit enter function.It is ideally a dropdown but i would like to achieve this by entering text "Colorado" in texbox and hit enter. The text box is located under a dropdown.My question is about how to enter text in Slenium textbox and hit Enter.
The HTML for textbox is as follows,
<input type="text" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" class="select2-input" role="combobox" aria-expanded="true" aria-autocomplete="list" aria-owns="select2-results-1" id="s2id_autogen1_search" placeholder="" aria-activedescendant="select2-result-label-11">
My current code is as follows:-
driver.findElement(By.cssSelector("#s2id_regionSelect > a > span.select2-arrow")).click();
driver.findElement(By.cssSelector("#s2id_autogen1_search")).sendKeys("Colorado");
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
WebElement textbox = driver.findElement(By.cssSelector("#s2id_autogen1_search"));
textbox.sendKeys(Keys.ENTER);
It is able to enter text in textbox but does not hit enter. I just need to select the Colorado state and click on different tab.
One way to do this is to just send a newline character (\n) with the text, e.g.
driver.findElement(...).sendKeys("Colorado\n");
In my C# automation code, I'm using the Actions(OpenQA.Selenium.Interactions) to hit enter in a input field.
new Actions(driver).SendKeys(Keys.Enter).Perform();
you can try to use TAB key:
WebElement textBox =driver.findElement(By.cssSelector("#s2id_autogen1_search")).sendKeys("Colorado");
textbox.sendKeys(Keys.TAB);// it will change focus to next element
//locate the elements in the page using their properties like``id, name or path etc.
WebElement email = driver.findElement(By.id("abc"));
email.sendKeys("abc#gmail.com");

Uploading Files Not Working - trim the initial characters

I am trying to upload a file using the WebBrowser control. It trims the starting character sometimes one and sometimes three then choose window gives error Invalid file name!. Can't seem to do it and need some help.
Here is the Html:
<input name="UploadedFile" id="UploadedFile" type="file" />
<input name="up" id="up" type="button" value="Upload" />
Here is the vb code:
Dim el = elc.GetElementsByName("UploadedFile")
el.Item("UploadedFile").Focus()
' SendKeys.Send("Capture.png" & "{ENTER}")
SendKeys.Send("C:\Capture.png" + "{ENTER}")
el.Item("UploadedFile").InvokeMember("Click")
that the file upload button comes up and hit enter, but can't input full filename into the file name area.
If I use thisSendKeys.Send("C:\Capture.png" + "{ENTER}"). It gives this error:
Choose window error screenshot
If I use this SendKeys.Send("Capture.png" + "{ENTER}"). It gives this error:
Choose window error screenshot
And if I put extra character then it works fine but it doesn't always trim one character so I can't put an extra character to solve this error.
The problem might be that the sendkeys comes up too fast behind focus, so the first few characters don't get picked up. Try just filling the textbox all at once with one line by setting the textbox's value rather than trying to imitate user keystrokes, this could replace both the focus and sendkeys lines:
WebBrowser1.Document.GetElementById("UploadedFile").SetAttribute("value", "C:\Capture.png")
...and then call the button-click
You are right #soohoonigan the sendkeys comes up too fast but that is not an answer for that. I did this like that.
Here is my code:
Dim el = elc.GetElementsByName("UploadedFile")
SetFile()
el.Item("UploadedFile").InvokeMember("Click")
Public Async Sub SetFile()
Await Task.Delay(1000)
SendKeys.Send("c:\Capture.png" & "{ENTER}")
End Sub
It's working fine.

Getting Visual Basic Program to Type into an HTML <p> and <input> tag with no id/name

So I have a program that takes a few inputs from textboxes and then adds them all up into two strings. Basically here is the problem, I am trying to get one of the strings to go into the forum post "title" and one into the forum "body". (This is not a spam program, it makes it easier for people to post ban reports for players on our server.) Here is the HTML codes for the website I am trying to type into;
<p class="ipsField_content">
<input id="topic_title" class="input_text" type="text" size="60" maxlength="150" name="TopicTitle" value="" tabindex="2">
</p>
The HTML code above is for the topic title area I want to type into. The problem with this is that it always says how it can not find this area.
'This is the HTML code for the forum body:
<body spellcheck="true" class="cke_show_borders">
<p>This is where I want to be able to type</p>
</body>`
With the HTML code above, I can't seem to get this VB code below to select that text area and enter in my string.
WebBrowser1.Document.GetElementsByTagName("p").InnerText = post
One reason is because VB doesn't allow me to use .innertext on a tag, and the other is that I do not know how to really specify which "p" tag. Like there is multiple "p" tags on this webpage, but it is the only "p" inside the "body" tag, if I could specify that somehow.
Here is the VB code I am using currently for the program.
Dim Report As String
Report = YourName & Suspect2 & Server & Time2 & Reason & RulesBroken & Proof
Dim topictitle As String
topictitle = ("" & Suspect & " - " & txtReason.Text & txtReasonCustom.Text & "")
txtTitle.Text = topictitle
txtPost.Text = Report`
making sure that the words "sign out" is on the page to insure the webbrowser is signed in.
`Dim theElementCollection As HtmlElementCollection
theElementCollection = WebBrowser1.Document.GetElementsByTagName("input")
For Each curElement As HtmlElement In theElementCollection
Dim controlName As String = curElement.GetAttribute("name").ToString
If WebBrowser1.DocumentText.Contains("Sign Out") Then
WebBrowser1.Navigate("www.ThisLinksToMakeNewPostOnTheWebsite.com")
WebBrowser1.Document.GetElementById("topic_title").InnerText = txtTitle.Text
WebBrowser1.Document.GetElementByTagName("body").firstchild.InnerText = txtPost.Text
End If`
this code below is used to click the submit button
`WebBrowser1.Document.Forms(0).InvokeMember("submit")`
also this is the html code for the "Post New Topic" button
<input type="submit" name="dosubmit" value="Post New Topic" tabindex="50" class="input_submit" accesskey="s">
Anyways that is it. I tried to include as much information and as much lines of code as I could to show that I really am trying.
Please help, I have tried the MSDN links, but I can't seem to apply it to this.
From your code I think you are using the WebBrowser control. There is a much less resource hogging alternative. Since you are really only interested in posting to a form, you don't need the overhead of a browser. You can use the HTTPWebRequest to POST the data/text from your textboxes directly to a URL. An example can be found here:
http://howtostartprogramming.com/vb-net/vb-net-tutorial-51-httpwebrequest-post-method/
It's not the best tutorial in the world but it will get you on your way. You would of course still need to know what data you need to send to the web site.

WebDriver SendKeys Doesn't Send Value

I am trying to run selenium webdriver, imitating typing something to textbox and submit it.
I have this following code:
WebElement element = null;
element = waitForElementPresent(tFByCssSelector,timeoutValue);
element.clear();
element.click();
element.sendKeys("Input String");
The code successfully type "Input String" to the textField, but when I submit the form, it says the form is empty (The form had been set to catch empty input exception).
I wonder why sendKeys does not set the value of the text field even though it has typed the wanted value into the text field.
Try to tab out of the field:
element.sendKeys("Input String");
element.sendKeys(Keys.TAB);
It may be that the field value only gets set on blur.
As I see, all looks okay in your selenium code. I believe there is some problem with your HTML form.
The form should have proper action for receiving the values. A sample form is provided below.
<form action="http://foo.com" method="post">
<input name="say" value="Hi">
<input name="to" value="Mom">
<button>Send my greetings</button>
</form>
Based on what you use in method parameter, you will get the form data in POST or GET variables.
Also you don't need to click on the element before sending keys in Selenium.