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)
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
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
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.
The examples you provided are very valuable, thank you very much for your support.
In the code mentioned below, what should I do to click on the 2nd or 3rd button instead of the first button?
{
let info, row, column, link
info = document.getElementById('information');
row = info.firstElementChild;
column = row.firstElementChild;
link = column.firstElementChild;
if (link) {
link.click();
}
}
If you have a link to more demos prepared for VFP, I would be happy if you could share it. Thanks again.
There are multiple ways to do that.
First look at the html again.
As you can see in the image above, the second button is the 2nd link element within the div column element.
You could for example use the javascript nextElementSibling to get the object for the 2nd element.
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 = link.nextElementSibling;
link.click();
}
}
ENDTEXT
Getting the 3rd or 4th etc.. element would be a matter of "next next" until you reached the element of interest.
Do-able for the 3rd element I guess, but beyond that you'll get code that is hard to read/understand.
In that case it might be better to enumerate all the child objects and access them by index, by using the javascript children method.
The code then could look like this:
Code:
LOCAL lcjScript
lcjScript = ''
TEXT TO lcjScript NOSHOW PRETEXT 7
() => {
let info, row, column, links
info = document.getElementById('information');
row = info.firstElementChild;
column = row.firstElementChild;
links = column.children;
if (links.length>0) {
links[1].click();
}
}
ENDTEXT
More VFP example code would be great and it is on our wish list, but it will probably take some more time as we are working on the control itself. But don't hesitate to ask here if you need assistance and we'll be happy to provide code snippets.
There are multiple ways to do that.
First look at the html again.
As you can see in the image above, the second button is the 2nd link element within the div column element.
You could for example use the javascript nextElementSibling to get the object for the 2nd element.
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 = link.nextElementSibling;
link.click();
}
}
ENDTEXT
Getting the 3rd or 4th etc.. element would be a matter of "next next" until you reached the element of interest.
Do-able for the 3rd element I guess, but beyond that you'll get code that is hard to read/understand.
In that case it might be better to enumerate all the child objects and access them by index, by using the javascript children method.
The code then could look like this:
Code:
LOCAL lcjScript
lcjScript = ''
TEXT TO lcjScript NOSHOW PRETEXT 7
() => {
let info, row, column, links
info = document.getElementById('information');
row = info.firstElementChild;
column = row.firstElementChild;
links = column.children;
if (links.length>0) {
links[1].click();
}
}
ENDTEXT
More VFP example code would be great and it is on our wish list, but it will probably take some more time as we are working on the control itself. But don't hesitate to ask here if you need assistance and we'll be happy to provide code snippets.
(2023-11-08, 15:05:52)wila Wrote: Hi,
There are multiple ways to do that.
First look at the html again.
As you can see in the image above, the second button is the 2nd link element within the div column element.
You could for example use the javascript nextElementSibling to get the object for the 2nd element.
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 = link.nextElementSibling;
link.click();
}
}
ENDTEXT
thisform.oAntViewDocument.RunAnonymousFunction( 1, "", lcjScript)
Getting the 3rd or 4th etc.. element would be a matter of "next next" until you reached the element of interest.
Do-able for the 3rd element I guess, but beyond that you'll get code that is hard to read/understand.
In that case it might be better to enumerate all the child objects and access them by index, by using the javascript children method.
The code then could look like this:
Code:
LOCAL lcjScript
lcjScript = ''
TEXT TO lcjScript NOSHOW PRETEXT 7
() => {
let info, row, column, links
info = document.getElementById('information');
row = info.firstElementChild;
column = row.firstElementChild;
links = column.children;
if (links.length>0) {
links[1].click();
}
}
ENDTEXT
thisform.oAntViewDocument.RunAnonymousFunction( 1, "", lcjScript)
More VFP example code would be great and it is on our wish list, but it will probably take some more time as we are working on the control itself. But don't hesitate to ask here if you need assistance and we'll be happy to provide code snippets.
--
Wil
Thank you very much.
The code I wrote to click the button with the "Listele" Id on the web form and submit it is not working. I wonder where I might be making a mistake?
2023-11-13, 06:20:28 (This post was last modified: 2023-11-13, 07:27:55 by ozcan.)
(2023-11-10, 22:04:34)wila Wrote: Hi Ozcan,
Your code looks fine to me.
Is the input control part of a html form?
Do you have a link to the page above that I can try and see what is happening?
--
Wil
Thank you very much Wil.
This website is accessed through two-factor authentication system.
I am sending the entire HTML content (and screenshot of inspect element) in the attachment.
I want to click "Listele" button and submit the form.
Thank you.
For some reason the default requestSubmit function isn't working. Will try to figure out why that is.
The following however might be able to work around the issue.
Code:
LOCAL lcjScript
LOCAL lbIsSuccess
LOCAL leStatus As Long
LOCAL leError As Integer
lcjScript = ''
TEXT TO lcjScript NOSHOW PRETEXT 7
() => {
let listele
listele = document.getElementById('btnListele');
if (listele) {
listele.click();
}
}
ENDTEXT
thisform.oAntView.navigateSync("https://antwise.com/demo/20231113-formSubmitButton.html",lbIsSuccess,leStatus)
thisform.oAntViewDocument.RunAnonymousFunction( 1, "", lcjScript)
Your button has a onclick event, so instead of triggering submit, we're triggering the onclick event by programmatically sending a click.
The reason it doesn't work, is because the form is using method type "post".
This shouldn't be a problem and is considered a bug.
Let me know if the workaround I supplied works for you and we'll add some functionality to handle this automatically.
--
Wil
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)
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
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
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
Hi.
Sorry. Why this text '() =>' before brackets?
It's beeing part of the lcjScript variable.
I don't understand that.
2023-11-24, 19:07:01 (This post was last modified: 2023-11-24, 19:12:22 by wila.)
(2023-11-24, 18:39:33)carlos@agpsoftware.com Wrote: Hi.
Sorry. Why this text '() =>' before brackets?
It's beeing part of the lcjScript variable.
I don't understand that.
Hello Carlos,
Don't be confused, it's a short hand notation detail from javascript.
It's called an arrow function.
The runAnonymousFunction depends on something that is called anonymous functions in javascript.
So basically a function without a name.
You can still pass variables though, that's why the () is there, so you can pass variables in there. (Click on the runAnonymousFunction link to see an example)
(2023-11-24, 18:39:33)carlos@agpsoftware.com Wrote: Hi.
Sorry. Why this text '() =>' before brackets?
It's beeing part of the lcjScript variable.
I don't understand that.
Hello Carlos,
Don't be confused, it's a short hand notation detail from javascript.
It's called an arrow function.
The runAnonymousFunction depends on something that is called anonymous functions in javascript.
So basically a function without a name.
You can still pass variables though, that's why the () is there, so you can pass variables in there. (Click on the runAnonymousFunction link to see an example)
Thank you for asking as it made it clear that the documentation could use a little bit extra info about arrow functions.
This has been added and will be in the next update.
--
Wil