Page 1 of 1

Browser Widget LC button to fill and submit form

Posted: Thu Sep 05, 2019 8:06 am
by adxsoft
Using the Browser Widget in LC8/9, I have retrieved an html page from my web server that has several input fields in an html form and am trying to figure out how to write some LC code that can fill in the input fields and submit the web page. In this way I can achieve my objective to use LC to sign into my web server, perform some queries and return my stats data back to a LC field or grid.

Any help appreciated

Allan

Re: Browser Widget LC button to fill and submit form

Posted: Sat Sep 07, 2019 8:59 pm
by [-hh]
You can do all that from LC with JavaScript (no other way).
Simply use do <string> in widget "Browser".
Important: The <string> has to be ONE line, use ";" between JS commands.

For example (the field containes no quotes, use single quotes as \' instead or work around).

Code: Select all

on mouseUp
  put fld "Textarea" into str
  replace cr with "\n" in str
  do "document.getElementById('myTextarea')." & \
     "value='" &str& "';" in widget "Browser"
end mouseUp
p.s. Questions to widgets, especially the browser widget, are better visible in the LCB forum (LiveCode Builder).

Re: Browser Widget LC button to fill and submit form

Posted: Sat Sep 07, 2019 10:28 pm
by SparkOut
Well you can't go wrong with help from Hermann, but if your objective is to log in and download data to view in LiveCode rather than interacting with a browser widget, you might find it possible to do this directly in LiveCode script (as opposed to LCB and/or javascript to leverage browser widget functionality)
This thread is old but still workable and may give some ideas viewtopic.php?f=7&t=16602&p=87985

Re: Browser Widget LC button to fill and submit form

Posted: Sun Sep 08, 2019 11:42 am
by mrcoollion
Maybe this java browser integration tutorial can help ?
Livecode Javascript communication
https://www.youtube.com/watch?v=xI_4PS_18uM&t=19s

regards,

Paul

Re: Browser Widget LC button to fill and submit form

Posted: Tue Sep 10, 2019 11:34 am
by [-hh]
The method described in the tutorial uses the revBowser external. This is available since LC 6.7.
So nothing new, but some thing is old:

The newer HTML5 (canvas) methods, say past 2010, are supported by revBrowser ONLY on Mac, NOT on Windows.

So be aware of that when using newer HTML5 methods/libraries with that external.
But using javascript in a browser widget works on Mac, Win and all Ubuntu flavours.

Re: Browser Widget LC button to fill and submit form

Posted: Sat Apr 11, 2020 3:08 am
by adxsoft
Thanks everyone. Used the Javascript approach and now submitting forms successfully.
Cheers
Allan

Re: Browser Widget LC button to fill and submit form

Posted: Tue Jan 05, 2021 7:43 pm
by simon.schvartzman
Hi all, I's like to use the Javascript approach to submit a form to upload a file to a web server. I'm confussed about to what exactly 'myTextarea' is referring to in the piece of code provided by Hermann

Code: Select all

on mouseUp
  put fld "Textarea" into str
  replace cr with "\n" in str
  do "document.getElementById('myTextarea')." & \
     "value='" &str& "';" in widget "Browser"
end mouseUp
Just to make myself more clear the page I want to "cheat" looks like this
Screen Shot 2021-01-05 at 15.38.46.png
Screen Shot 2021-01-05 at 15.38.46.png (8.29 KiB) Viewed 9605 times


and I'd like my LC script to fill in the file name (which I already know) and "press" the Submit button.

I'd really appreciate any help with it.
Many thanks in advance