Dent Posted May 19, 2016 Share Posted May 19, 2016 I'm trying to set values on this site http://nationwide-intermediary.co.uk/calculators/aff_calc which I can do using _IEFormElementSetValue however when I then submit the completed page the page throws errors as if the fields contain no data. Setting focus on each field and using Send does work, but is slow and prone to errors. Here's a section of code that completes everything on the first page and clicks continue. expandcollapse popup#include <IE.au3> ;#include <File.au3> Local $oIE = _IECreate("http://nationwide-intermediary.co.uk/calculators/aff_calc") If Not IsObj($oIE) Then Exit ConsoleWrite("Error in $oIE" & @CRLF) Local $oIE = _IEAttach("Affordability Calculator | Nationwide for Intermediaries (NFI)") _IELoadWait($oIE) Local $oClassReturn = $oIE.document.getElementsByClassName("pageContainer page0") If Not IsObj($oClassReturn) Then Exit ConsoleWrite("Error in $oClassReturn" & @CRLF) Local $oTagReturn = $oClassReturn.Item(0).getElementsByTagName("li") If Not IsObj($oTagReturn) Then Exit ConsoleWrite("Error in $oTagReturn" & @CRLF) For $loop = 1 to 2 $oTagReturn.Item(1).click() ; Item(1) = "Buy a new property" / Item(2) = "Remortgage" | Running the command twice is require to close the drop-down Next Local $oMtgAmt = _IEGetObjByName($oIE, "bespAppCharsMiscLoanAmountRequested") ;_IEFormElementSetValue($oMtgAmt, "100000") ;_IEAction($oMtgAmt, "focus") ;Send("{DEL}") _IEFormElementSetValue($oMtgAmt, "100000") ;Send("100000") Local $oMtgTermYrs = _IEGetObjByName($oIE, "bespAppCharsMiscTermRequestedYY") _IEFormElementSetValue($oMtgTermYrs, "25") ;_IEAction($oMtgTermYrs, "focus") ;Send("25") Local $oMtgTermMths = _IEGetObjByName($oIE, "bespAppCharsMiscTermRequestedMM") _IEFormElementSetValue($oMtgTermMths, "00") ;_IEAction($oMtgTermMths, "focus") ;Send("00") Local $oTagReturn = $oClassReturn.Item(0).getElementsByTagName("input") If Not IsObj($oTagReturn) Then Exit ConsoleWrite("Error in $oTagReturn" & @CRLF) $oTagReturn.Item(4).click() ; Item(3) = One Applicant / Item(4) = Two Applicants Local $oTagReturn = $oClassReturn.Item(0).getElementsByTagName("li") If Not IsObj($oTagReturn) Then Exit ConsoleWrite("Error in $oTagReturn" & @CRLF) For $loop = 1 to 2 $oTagReturn.Item(4).click() ; Item(4) = Standard / Item(5) = Equity Share / Item(6) = Right to Buy / Item(7) = Shared Ownership | Running the command twice is require to close the drop-down Next Local $oTagReturn = $oClassReturn.Item(0).getElementsByTagName("input") If Not IsObj($oTagReturn) Then Exit ConsoleWrite("Error in $oTagReturn" & @CRLF) $oTagReturn.Item(5).click() ; Item(5) = Have they found a new home yet 'Yes' / Item(6) = Have they found a new home yet 'No' Local $oTagReturn = $oClassReturn.Item(0).getElementsByTagName("li") If Not IsObj($oTagReturn) Then Exit ConsoleWrite("Error in $oTagReturn" & @CRLF) For $loop = 1 to 2 $oTagReturn.Item(9).click() ; Item(9) = Freehold / Item(10) = Leasehold / Item(11) = Commonhold / Item(12) = Ownership Scotland | Running the command twice is require to close the drop-down Next For $loop = 1 to 2 $oTagReturn.Item(14).click() ; Item(14) = Detached House / Item(15) = Detached Bungalow / Item(16) = Semi-Detached Bungalow / Item(17) = Terraced Bungalow / Item(18) = Semi-Detached House / Item(19) = Terraced House / Item(20) = Purpose built flat/maisonette / Item(21) = Converted flat/maisonette | Running the command twice is require to close the drop-down Next Local $oPP = _IEGetObjByName($oIE, "bespAppCharsMiscExpectedPurchasePriceMSO") ;_IEAction($oPP, "focus") ;Send("{DEL}") _IEFormElementSetValue($oPP, "200000") ;Send("200000") Local $oDOBAppOne = _IEGetObjByName($oIE, "bespMainAppDateOfBirth") _IEFormElementSetValue($oDOBAppOne, "01011990") ;_IEAction($oDOBAppOne, "focus") ;Send("01011990") Local $oDOBAppOne = _IEGetObjByName($oIE, "bespJointAppDateOfBirth") _IEFormElementSetValue($oDOBAppOne, "01011990") ;IEAction($oDOBAppOne, "focus") ;Send("01011990") Local $oClassReturn = $oIE.document.getElementsByClassName("pageContainer page1") If Not IsObj($oClassReturn) Then Exit ConsoleWrite("Error in $oClassReturn" & @CRLF) Local $oTagReturn = $oClassReturn.Item(0).getElementsByTagName("li") If Not IsObj($oTagReturn) Then Exit ConsoleWrite("Error in $oTagReturn" & @CRLF) For $loop = 1 to 2 $oTagReturn.Item(1).click() ; Item(1) = Male / Item(2) = Female | Applicant one Next For $loop = 1 to 2 $oTagReturn.Item(5).click() ; Item(4) = Male / Item(5) = Female | Applicant two Next Local $oTagReturn = $oClassReturn.Item(0).getElementsByTagName("input") If Not IsObj($oTagReturn) Then Exit ConsoleWrite("Error in $oTagReturn" & @CRLF) $oTagReturn.Item(2).click() ; Item(2) = Has dependents / Item(3) = No dependents | Applicant one $oTagReturn.Item(4).click() ; Item(4) = Has dependents / Item(5) = No dependents | Applicant one Local $oDependentsZeroToFiveAppOne = _IEGetObjByName($oIE, "bespMainAppMmrMDependantsAgeRange1") ;_IEAction($oDependentsZeroToFiveAppOne, "focus") ;Send("{DEL}") _IEFormElementSetValue($oDependentsZeroToFiveAppOne, "1") ;Send("1") Local $oDependentsSixToElevenAppOne = _IEGetObjByName($oIE, "bespMainAppMmrMDependantsAgeRange2") ;_IEAction($oDependentsSixToElevenAppOne, "focus") ;Send("{DEL}") _IEFormElementSetValue($oDependentsSixToElevenAppOne, "2") ;Send("2") Local $oDependentsTwelveToSeventeenAppOne = _IEGetObjByName($oIE, "bespMainAppMmrMDependantsAgeRange3") ;_IEAction($oDependentsTwelveToSeventeenAppOne, "focus") ;Send("{DEL}") _IEFormElementSetValue($oDependentsTwelveToSeventeenAppOne, "3") ;Send("3") Local $oDependentsEighteenPlusAppOne = _IEGetObjByName($oIE, "bespMainAppMmrMDependantsAgeRange4") ;_IEAction($oDependentsEighteenPlusAppOne, "focus") ;Send("{DEL}") _IEFormElementSetValue($oDependentsEighteenPlusAppOne, "4") ;Send("4") Local $oDependentsZeroToFiveAppTwo = _IEGetObjByName($oIE, "bespJointAppMmrJDependantsAgeRange1") ;_IEAction($oDependentsZeroToFiveAppTwo, "focus") ;Send("{DEL}") _IEFormElementSetValue($oDependentsZeroToFiveAppTwo, "1") ;Send("1") Local $oDependentsSixToElevenAppTwo = _IEGetObjByName($oIE, "bespJointAppMmrJDependantsAgeRange2") ;_IEAction($oDependentsSixToElevenAppTwo, "focus") ;Send("{DEL}") _IEFormElementSetValue($oDependentsSixToElevenAppTwo, "2") ;Send("2") Local $oDependentsTwelveToSeventeenAppTwo = _IEGetObjByName($oIE, "bespJointAppMmrJDependantsAgeRange3") ;_IEAction($oDependentsTwelveToSeventeenAppTwo, "focus") ;Send("{DEL}") _IEFormElementSetValue($oDependentsTwelveToSeventeenAppTwo, "3") ;Send("3") Local $oDependentsEighteenPlusAppTwo = _IEGetObjByName($oIE, "bespJointAppMmrJDependantsAgeRange4") ;_IEAction($oDependentsEighteenPlusAppTwo, "focus") ;Send("{DEL}") _IEFormElementSetValue($oDependentsEighteenPlusAppTwo, "4") ;Send("4") $oTagReturn.Item(15).click() ; Item(14) = Is retired / Item(15) = Not retired | Applicant one $oTagReturn.Item(17).click() ; Item(16) = Is retired / Item(17) = Not retired | Applicant one Local $oRetAgeAppOne = _IEGetObjByName($oIE, "bespMainAppMExpectedRetirementAge") _IEFormElementSetValue($oRetAgeAppOne, "65") ;_IEAction($oRetAgeAppOne, "focus") ;Send("65") Local $oRetAgeAppTwo = _IEGetObjByName($oIE, "bespJointAppJExpectedRetirementAge") _IEFormElementSetValue($oRetAgeAppTwo, "65") ;_IEAction($oRetAgeAppTwo, "focus") ;Send("65") Local $oTagReturn = $oIE.document.getElementsByTagName("button") If Not IsObj($oTagReturn) Then Exit ConsoleWrite("Error in $oTagReturn" & @CRLF) $oTagReturn.Item(1).Click() Exit Link to comment Share on other sites More sharing options...
mLipok Posted May 19, 2016 Share Posted May 19, 2016 (edited) Little Recently I notice that $oIE.document.getElementsByClassName("pageContainer page0") Do not work when class name contains spaces. Can you confirm ? Can you try this following _IEQuerySelectorAll() function as a replacement for .getElementsByClassName Methode ?: Edited May 19, 2016 by mLipok Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24 Link to comment Share on other sites More sharing options...
Dent Posted May 20, 2016 Author Share Posted May 20, 2016 Hi mLipok, $oIE.document.getElementsByClassName("pageContainer page0") This works ok for me, but I did notice on another machine today that it did not work with an older version of IE installed but it began working fine after I upgraded to IE11 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now