Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
VFP Web automation and form filling
#2
Hello Ozcan,

Here's some example code in VFP to do what you asked.
This is based on the demo code that is pre-installed.

First some code to automatically open the website in the init procedure of the form.

Code:
thisform.oAntviewDocument = CREATEOBJECT('AntViewAx.AntViewDocument') && create the AntViewDocument and assign it to a form property thisform.oAvdCtrl = NEWOBJECT('avdctrl','avdctrl.prg') && CREATEOBJECT("Ctrl") && We need an object for our events EVENTHANDLER(this.oAntviewDocument,this.oAvdCtrl) thisform.oAntView.Init() thisform.oAntView.UnlockControl("ExampleCompany","WI5PO2-2KSU3Q-HWFXFU-IUMU2V-QF8P2F") lnStatus = thisform.oAntView.UnlockStatus thisform.oAntviewDocument.CurrentBrowser = thisform.oAntView.object && this property shows as "Write-only" in the object browser thisform.text1.Value = [https://eokulyd.meb.gov.tr/] thisform.oAntView.object.navigate(ALLTRIM(thisform.text1.Value))

To automatically click on the link "button" I've written the following bit in the click method of the LoadString button:
Code:
LOCAL lcjScript lcjScript = '' TEXT TO lcjScript NOSHOW PRETEXT 7 () => {       let info, row, column, link       info = document.getElementById('information');       row = info.firstElementChild;       column = row.firstElementChild;       link = column.firstElementChild;       if (link) {         link.click();       }     } ENDTEXT thisform.oAntViewDocument.RunAnonymousFunction( 1, "", lcjScript)

Normally you should check that each of those get element object methods actually returns an object.
So the error handling is missing I expect that you can write that yourself.

It clicked the left hand "button" during my tests.

For "checking" a checkbox in a form I added the following to the "go" button click method:


Code:
LOCAL lcjScript LOCAL lbIsSuccess LOCAL leStatus lcjScript = '' TEXT TO lcjScript NOSHOW PRETEXT 7 () => {       let obj       obj = document.getElementById('auto');       if (obj) {         obj.setAttribute("checked","");       }     } ENDTEXT thisform.oAntView.navigateSync("https://antwise.com/demo/SimpleCheckboxExample.html",lbIsSuccess,leStatus) thisform.oAntViewDocument.RunAnonymousFunction( 1, "", lcjScript)


This first navigates to the page https://antwise.com/demo/SimpleCheckboxExample.html which has 3 checkboxes with all of them unchecked. Then it checks the "I have a car" checkbox immediately after loading the page.

This last example makes it clear that it would be really great to have a method for setting a element attribute in the document interface without having to resort to javascript in your code.
Which will be looked into.

Hope this helps,
--
Wil
Reply


Messages In This Thread
VFP Web automation and form filling - by ozcan - 2023-11-07, 12:38:29
RE: VFP Web automation and form filling - by wila - 2023-11-07, 18:26:06
RE: VFP Web automation and form filling - by wila - 2023-11-24, 19:07:01
RE: VFP Web automation and form filling - by wila - 2023-11-28, 11:50:05
RE: VFP Web automation and form filling - by wila - 2023-11-08, 15:05:52
RE: VFP Web automation and form filling - by wila - 2023-11-10, 22:04:34
RE: VFP Web automation and form filling - by wila - 2023-11-13, 12:43:43
RE: VFP Web automation and form filling - by wila - 2023-11-13, 15:39:07

Forum Jump:


Users browsing this thread: 1 Guest(s)