PDA

View Full Version : Sleeper: Issues getting text into a text box on a website form



cfernand74
04-10-2014, 11:21 AM
Need help trying to code getting text into a text box on a web form. I know how to create code to enter text into textbox, click a submit button and clicking internal links within a website. Of the different website that I use on a regular bases to fill out there form there are three that I can't seem to be able gain any access to within it to fill the form. Unfortunately these website are password protected by me. But I will give as much info to see if you guys can help me.

I have been at this for about two weeks now and thought I would be able to resolve myself. But here I am. Looks like lots of knowledgeable people come to this website to solve other people’s issues. Hope I can be helped. I am new to VBA, but I am a quick learner. What I do is create a similar form on Excel then transfer that info to the website form. Which I can do for several different companies. I think I have tried just about everything the three that I am not able to get this done for. Heck I may have had the right code, but maybe I didn't know how to tweak it the right way to make it work for me.

The first issue might be that all subpages to the main page of the website use the same URL as the main Page
example:
This page shows after login:------------------- http://www.websitename.com/main.aspx
This page comes up after following internal link--http://www.websitename.com/main.aspx
Then follow internal link to target page----------http://www.websitename.com/main.aspx

After I am in no code I have tried works. I have tried getting to target page by following links with code but that doesn't work either. I can view the source code.
I have tried looping looking for Name and ID and the input reference.

Target page appears not to have a title <title></title> to navigate to so I use the main page and call it as the IE active page while it’s open. But I can't tell if I am on target page.

I have read on the internet that issues may come up with website that use frame. And it appears like these website use frame. Here is the code that shows a frame. I have tried other codes found on the internet that dealt with frame but not been able to make work.

HTML from Target page:


<frameset id="_FRAMESET_TOP" rows="78px,*" border="0" frameborder="0" framespacing="0" onresize="if(window.netscape){history.go(0);}">
<frame name="_TOP_MENU" src="top_menu.aspx" frameborder="0" noresize="" scrolling="no">
<frameset id="_FRAMESET_SIDE" cols="0px,*" border="1" frameborder="0" onresize="if(window.netscape){history.go(0);}">
<frame name="_SIDE_MENU" src="/search/info.aspx" scrolling="yes">
<frame name="_MAIN" src="vweb/welcome.aspx">
</frameset>
</frameset>
<frame name="_TOP_MENU" src="top_menu.aspx" frameborder="0" noresize="" scrolling="no">
<frameset id="_FRAMESET_SIDE" cols="0px,*" border="1" frameborder="0" onresize="if(window.netscape){history.go(0);}">
<frame name="_SIDE_MENU" src="/search/info.aspx" scrolling="yes">
<frame name="_MAIN" src="vweb/welcome.aspx">
</frameset>




' Use existing webiste with option to open new one by changing last part of the code if not found
Public Sub SubjectHistory()
Dim objSW As SHDocVw.ShellWindows
Dim objIE As SHDocVw.InternetExplorer
Dim Forms As HTMLFormElement
Dim IE As Object
Dim bAppRunning As Boolean
Set objSW = New SHDocVw.ShellWindows
If objSW.Count Then 'new
For Each IE In objSW
'you can change from url to title by ie.LocationURL to ie.LocationName
If InStr(1, IE.LocationName, "Google") Then ‘have google page already open Test good
bAppRunning = True
IE.Visible = True
Do
DoEvents
Loop Until IE.ReadyState = 4
Exit For
End If
Next IE
End If
'My Code Starts
'IE.Document.getElementsByName("q")(0).Value = "test8" 'Tested on Google search page and works
IE.Document.getElementsByName("PS_FORM/SUBJECT_PROPERTY/APN")(0).Value = "12345" 'tried byId and byTagName
'IE.Document.Forms("Form1").all("PS_FORM/SUBJECT_PROPERTY/APN").Value = "12345" 'found on website put Dim ref above
'IE.Document.all("PS_FORM/SUBJECT_PROPERTY/APN").Value = "12345"
' My Code Ends
If bAppRunning = False Then
'Set objIE = CreateObject("InternetExplorer.Application") ' new
'objIE.Visible = True
'objIE.Navigate "Enter Google search link here"
MsgBox "BPO Website not Opened Yet"
End If
Set objIE = Nothing
Set objSW = Nothing
End Sub

Sorry for the length, hopefully I was descriptive enough to get my questioned answered.

westconn1
04-11-2014, 03:48 AM
hopefully I was descriptive enough to get my questioned answered.no, to get help you would need to post source code for the frames and a more of the parent page source, indicate which frame contains the elements you wish to modify
without access to the original website, it is very difficult to suggest code that will work

cfernand74
04-12-2014, 06:45 AM
Found a sample website to test on so i can learn how to salve my problem. I have found a website that uses iframe if someone can show me how to access that frame and input the date 10/10/2013.
Here is test website:

http://jqueryui.com/datepicker/

I thought that using the code like i would when i use it for entering into a form would work but it doesn't.
Here is iframe html from website.

<iframe class="demo-frame" src="/resources/demos/datepicker/default.html"></iframe>
The code i use for forms:

'IE.Document.forms("FormName").all("datepicker").Value = Range("b54")

I tried changing it, but in this case this iframe doesn't even have a name or id, just a class. So would be good to learn how to access frame by Class also
'IE.Document.frames("demo-frame").all("datepicker").Value = Range("b54")

From reading so many post it appears there is a difference on accessing Iframes and frames, so i would need to know how to do both if there is a difference.

This is the code i am using to try access it. Note that you have to have the website already open, because this is the way i do things while working and transfering data instead of opening a new website page to the location.




Public Sub Dateinput()
Dim objSW As SHDocVw.ShellWindows
Dim objIE As SHDocVw.InternetExplorer
Dim IE As Object
Dim bAppRunning As Boolean
Set objSW = New SHDocVw.ShellWindows
If objSW.Count Then 'new
For Each IE In objSW
If InStr(1, IE.LocationURL, "http://jqueryui.com/datepicker/") Then
bAppRunning = True
IE.Visible = True
Do
DoEvents
Loop Until IE.ReadyState = 4
Application.Wait (Now() + TimeValue("0:00:3")) 'put this in because on some website the loop above fails
'start my code here
IE.Document.frames("demo-frame").all("datepicker").Value = '10/10/2013" 'this failed
'End my code ode here
Exit For
End If
Next IE
End If
If bAppRunning = False Then
'Set objIE = CreateObject("InternetExplorer.Application") ' new
'objIE.Visible = True
'objIE.Navigate "www.google.com"
MsgBox "BPO Website not Opened Yet"
End If
Set objIE = Nothing
Set objSW = Nothing
End Sub

westconn1
04-14-2014, 04:35 AM
you can test this code, to see if it works for you

Set wb = CreateObject("internetexplorer.application")
wb.navigate2 "http://jqueryui.com/datepicker/ "
wb.Visible = True
Do Until wb.readystate = 4: DoEvents: Loop
Set fr = wb.document.frames(0)
Set ele = fr.document.all("datepicker")
ele.Value = Date

modify to suit your requirements

cfernand74
04-14-2014, 05:56 AM
Not workiing yet.Thanks for trying to help. Do i have to make a reference to access frames or this type of date picker. Let my know what references i should have active to avoid errors.
Currently i have these references active:
Visual Basic for Applications
Microsoft Excel 12.0 Object library
OLE Automation
Microsoft Office 12.0 Object library
Microsoft forms 2.0 object library
Microsoft Internet Controls
Microsoft HTML object library

Also tried the code with the the date added below and received the following error:

Run-time error'2147352319(80020101)':
Automation errro

Did this code work for you?


Set wb = CreateObject("internetexplorer.application")
wb.navigate2 "http://jqueryui.com/datepicker/ "
wb.Visible = True
Do Until wb.readystate = 4: DoEvents: Loop
Set fr = wb.document.frames(0)
Set ele = fr.document.all("datepicker")
ele.Value = "10/10/2014"

Hangs on:

Set fr = wb.Document.Frames(0)

westconn1
04-14-2014, 06:07 AM
Did this code work for you?yes, put todays date in the box, no errors, the basic code uses latebinding and required no references at all to work
may require some delay for the frame to complete loading, even after the host page is ready, but i did not have a problem with that

cfernand74
04-14-2014, 06:30 AM
Odd that such a simple code would fail. Can you provide me the references that you have active, so i can test with your setting and rule out interference from other references. Also the date needs the quotation marks correct "10/10/2014"?

Also you said you got into the frame with late binding is that the case for accessing all frame within a website. I could have sworn that i had tried this. Hopefully i can resolve this issue with the Automation error. Maybe this is what has kept me out of accessing frames. Any thoughts welcomed.

westconn1
04-14-2014, 02:16 PM
Also you said you got into the frame with late binding is that the case for accessing all frame within a website.latebinding is using activexes without any references, saves problems with versions when working office applications, nothing to do with working with frames

it may be some issue with your version of internet explorer, that you can not access the frame, i know some times i can not load some sites on different computers, which appears to be internet explorer version issues


Also the date needs the quotation marks correct "10/10/2014"?of course if you use a literal string, not if it is a variable, or as i used, a function

try modifying your original code like
Public Sub Dateinput()
Dim objSW As SHDocVw.ShellWindows
Dim objIE As SHDocVw.InternetExplorer
Dim IE As Object
Dim bAppRunning As Boolean

Set objSW = New SHDocVw.ShellWindows
If objSW.Count Then 'new
For Each IE In objSW
If InStr(1, IE.LocationURL, "http://jqueryui.com/datepicker/") Then
bAppRunning = True
IE.Visible = True
Do
DoEvents
Loop Until IE.ReadyState = 4

Application.Wait (Now() + TimeValue("0:00:3")) 'put this in because on some website the loop above fails

'---------start my code here
Set fr = IE.document.frames(0)
Set dp = fr.document.all("datepicker")
dp.Value = "10/10/2013" 'this worked

'----------End my code ode here

Exit For
End If
Next IE
End If
If bAppRunning = False Then
'Set objIE = CreateObject("InternetExplorer.Application") ' new
'objIE.Visible = True
'objIE.Navigate "www.google.com"
MsgBox "BPO Website not Opened Yet"
End If


Set objIE = Nothing
Set objSW = Nothing
End Subyour original code would work like
IE.document.frames(0).document.all("datepicker").Value = Date
you must work with the document contained in the frame
if you are still having automation errors, try on a different computer, or try the first code sample (post #4) in a vbs script

cfernand74
05-31-2014, 03:50 PM
latebinding is using activexes without any references, saves problems with versions when working office applications, nothing to do with working with frames

it may be some issue with your version of internet explorer, that you can not access the frame, i know some times i can not load some sites on different computers, which appears to be internet explorer version issues

of course if you use a literal string, not if it is a variable, or as i used, a function

try modifying your original code like
Public Sub Dateinput()
Dim objSW As SHDocVw.ShellWindows
Dim objIE As SHDocVw.InternetExplorer
Dim IE As Object
Dim bAppRunning As Boolean

Set objSW = New SHDocVw.ShellWindows
If objSW.Count Then 'new
For Each IE In objSW
If InStr(1, IE.LocationURL, "http://jqueryui.com/datepicker/") Then
bAppRunning = True
IE.Visible = True
Do
DoEvents
Loop Until IE.ReadyState = 4

Application.Wait (Now() + TimeValue("0:00:3")) 'put this in because on some website the loop above fails

'---------start my code here
Set fr = IE.document.frames(0)
Set dp = fr.document.all("datepicker")
dp.Value = "10/10/2013" 'this worked

'----------End my code ode here

Exit For
End If
Next IE
End If
If bAppRunning = False Then
'Set objIE = CreateObject("InternetExplorer.Application") ' new
'objIE.Visible = True
'objIE.Navigate "www.google.com"
MsgBox "BPO Website not Opened Yet"
End If


Set objIE = Nothing
Set objSW = Nothing
End Subyour original code would work like
IE.document.frames(0).document.all("datepicker").Value = Date
you must work with the document contained in the frame
if you are still having automation errors, try on a different computer, or try the first code sample (post #4) in a vbs script

cfernand74
05-31-2014, 04:00 PM
I have figured how to make this work for me. And here is the the info. Hope this helps many. Thanks to those that offered their help.


'On my website there were regular website which i accessed with:
[CODE]IE.Document.getElementsByName("name goes here")(0).Value = "Test"
or

IE.Document.getElementsByName("name goes here")(0).Value = Range("B30")

Then there were website with forms which i accessed with:

IE.Document.forms("Form name goes here").all("element name goes here").Value = "Test"

Then there were website with frames which i accessed with:

IE.Document.Frames.Item("Frame name goes here").Document.all.Item("element name goes here").Value = "test"

cfernand74
02-15-2015, 12:51 PM
Posting new issue here as its similar and don't want to start new thread for similar issue.

Issue is company that I enter data into have changed there website form. Before I was able to transfer data in the usual way of:

IE.Document.getElementsByName("InspectionDate$txtMonth")(0).Value = Range("b54")
and

IE.Document.All("InspectionDate$txtMonth")(0).Value = Range("b54")

The code on there website has changed to:

<td> <input class="form-control input-sm ng-pristine ng-valid ng-touched" type="text" ng-model="tax.OwnerPubRec"></input></tr>

I have tried:

IE.Document.All("tax.OwnerPubRec).Value = Range("b57")

and


IE.Document.getElementsByng-model("tax.OwnerPubRec).Value = Range("b57")


The "ng-model" term holds all useful information but when I move out of the line code it separates it to "ng- model" with a space in between "ng-" and "model"
and then I try run code with its auto changed format and it fails to compile highlighting "model"

Any idea on how to search by "ng-model"

thanks

charles

cfernand74
02-17-2015, 12:37 PM
please help i need to resolve this issue ASAP!
thanks in advance.

I believe the "-" negative sign is causing the issue as "ng-model" is being broken up as the code execution goes through it. Is it possible to let the code know that "ng-model" goes together not separate so it can find the text box and i can enter the data into it.

Kyle234
02-20-2015, 03:04 AM
You can't search by "ng-model" that's a custom html tag used by Angular (a JavaScript framework). You could use .qetElementsByClassName, loop through them and check for that particular attribute though

cfernand74
02-25-2015, 10:16 PM
Thanks

Using .getelementsbyclassname did work as far as getting data into text box when i run the code. But when i try and press the web form save button it's as if i did not put anything inside the text box. It highlights all the text boxes noting that form is not complete. I can verify that it did not save also by going to a different web page and coming back to the original page and nothing was saved.

FYI: If i use keyboard and type into text box or copy and paste into text box and then i click the save button on web form it works as it should.

Also tried this: After running code and visually seeing text inside text box i then put the cursor prompt inside the text box and pressed the tab key along the text box's and then tried saving data. But no luck in recognizing that there is text inside text box.

Also tried: After the code runs and enters data into text box i then put the cursor prompt inside the text box and pressed the "Enter" key . Still no luck.
This is a weird web form that is behaving oddly.

So if there is no easy way of letting the website know that there is actual text inside the web form is there at least a way to make the website think that i am copying and pasting into the text box as that actually worked when i do it manually.

Again this is the type of code i am dealing with:

<td> <input class="form-control input-sm ng-pristine ng-valid ng-touched" type="text" ng-model="tax.OwnerPubRec"></input></tr>

cfernand74
03-02-2015, 07:19 AM
Anyone out there? Please help. Any suggestions welcomed.
It just happened another company changed there web form and having similar issues. But lets tackle this issue at hand first.
I think i have tried all i can think of.
Thanks in advance.

Kyle234
03-03-2015, 04:41 AM
You need to simulate a key press event so that the model updates, but I don't know how to do it with IE automation rather than using JavaScript