Jump to content

Fill in inputbox on IE - cannot connect to Form Element


Go to solution Solved by Danp2,

Recommended Posts

Hi,
 
I am having trouble connecting to a web page form. The inputbox I need to connect to cannot be found. all I can find on the page is this:
 
> input.hidden start
> input.hidden hitsOnPage
> input.hidden globalSearchActive
> input.hidden sortType
> input.text query
---- FORM 0 --------------------
> input.checkbox necessaryPerformance
> input.checkbox functional
> input.checkbox sharingTargeting
> input.submit 0

 

I think I have found the Form I need to connect to with Debugbar but to be honest im I have a lot to learn about IE and how it all works.

My code is below. Can anyone help?

#include <GUIConstantsEx.au3>
#include <Array.au3>
#include <GuiButton.au3>
#include <GuiEdit.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <IE.au3>


createIE()


Func createIE()


   Global $oIE = _IECreate("https://www.openreach.co.uk/orpg/home/newlogin.do?smauthreason=0&target=http%3A%2F%2Fwww.openreach.co.uk%2Forpg%2Fcustomerzone%2Fappointmentservices%2FloadGetAppointment.do&fromMasterHead=1")

   Local $oForm = _IEFormGetObjByName($oIE, "Login")
   Local $oText = _IEFormElementGetObjByName($oForm, "USER")
   _IEFormElementSetValue($oText, "***********") 


   Local $oText = _IEFormElementGetObjByName($oForm, "PASSWORD")
   _IEFormElementSetValue($oText, "************") 

   _IEFormSubmit($oForm)




   _IELoadWait($oIE)


   Local $sTexterror = _IEBodyReadText($oIE)
   Local $passworderror = StringInStr($sTexterror, "password has not been recognised")
    If $passworderror = 0 Then
      Navigate()

         Else
      MsgBox($MB_SYSTEMMODAL, "Login Failed", "Attempt again manually")
   EndIf
EndFunc

Func Navigate()

   _IELinkGetCollection($oIE)
   Local $oLinks = _IELinkGetCollection($oIE)
   Local $iNumLinks = @extended
   
   For $oLink In $oLinks
    If StringInStr($oLink.href, "loadFaultTracker.do") Then
      _IEAction($oLink, "click")
      ExitLoop
   EndIf
Next

   _IELoadWait($oIE)

   Local $sMyString = "Launch application"
   Local $oLinks = _IELinkGetCollection($oIE)
   For $oLink In $oLinks
   Local $sLinkText = _IEPropertyGet($oLink, "innerText")
    If StringInStr($sLinkText, $sMyString) Then
         MsgBox(0, "Form Info", "found your link")
        _IEAction($oLink, "click")
        ExitLoop
    EndIf
 Next

   _IELoadWait($oIE)
   Sleep(5000)




;~ ----------------------------------------------------------- Attempt to find form----------------------------------------------
$colForms = _IEFormGetCollection($oIE) ; get all forms
For $oForm In $colForms ; loop over form collection

    ConsoleWrite("---- FORM " & $oForm.name & " --------------------" & @CRLF)
    $oFormElements = _IEFormElementGetCollection($oForm) ; get all elements
    For $oFormElement In $oFormElements ; loop over element collection

        If StringLower($oFormElement.tagName) == 'input' Then ; it is an input
            ConsoleWrite("> input." & $oFormElement.type & " " & $oFormElement.name & @CRLF)
            _IEFormElementSetValue($oFormElement, "Found You", 0) ; set value of the field
        ElseIf StringLower($oFormElement.tagName) == 'textarea' Then ; it is a textarea
            ConsoleWrite("> textarea " & $oFormElement.name & @CRLF)
            _IEFormElementSetValue($oFormElement, "Found You", 0) ; set value of the field
        EndIf

    Next

Next
;~ --------------------------------------------------------------------------------------------------------------------------------

EndFunc
Link to comment
Share on other sites

Hi Danp2

When I run the script it logs into the site fine, it navigates through a couple of pages which is fine but then there is a page which has a form which I want the script to fill in but I cannot access the form. Using Debugbar I found the form name to be "MainForm" and the inputbox element (INPUT type=text name=fault_id_single)

So I tried:

Local $oForm = _IEFormGetObjByName($oIE, "MainForm")
Local $oText = _IEFormElementGetObjByName($oForm, "fault_id_single")
_IEFormElementSetValue($oText, "Test")

Inputbox does not fill in....I missing something obvious im sure!

Link to comment
Share on other sites

Not sure how I check for sure but if I look at the DOM section then HTML in Debugbar there is an IFRAME, if I hove mouse over the word IFRAME it highlights the section of the page which I need to interact with....

<IFRAME id=frame1 onload=autoResize(); height=191 src=

Is that what you mean?

 

Also I think its Javascript, does that matter?

Edited by talkfoodtalk
Link to comment
Share on other sites

Appreciate your help guys.

I still having problems tho. When I use

$oFrame = _IEFrameGetObjByName($oIE, "frame1")

I get the following

--> IE.au3 T3.0-1 Warning from function _IEFrameGetObjByName, $_IEStatus_NoMatch (No frames matching name)

I tried to use _IEFrameGetCollection with the example from the Autoit help file and it does display the text from the frame I need to fill in however im not sure how I can get the frame obj name.

The frame seems to be a different URL as well....not sure if that is relavant....

Any additional ideas?

Edited by talkfoodtalk
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...