Page 1 of 1

Question for Andrew

Posted: Fri Jul 16, 2010 12:57 am
by lohill
Hi Andrew,

I apologize in advance for asking you for more help but as I come back to the problem that has been haunting me for months, I find that the advice and examples you have given me in the past have been most helpful. The problem for me is still accessing data found on web pages that require logon. You gave me an example of code of a login situation that you had created. Here is the code for the mouseUp that you gave me?

Code: Select all

on mouseUp
local tBrowserId
  
   put revBrowserOpen(the windowId of this stack, "http://buriedtreasure.com.au/fakesecure.php") into tBrowserId
   revBrowserSet tBrowserId, "rect", "0,0,800,800"
   if tBrowserId is not an integer then answer "Failed to open browser"
   wait 10 seconds
  
   -- populate fields
   get revBrowserExecuteScript(tBrowserId, "document.form1.user.value = 'demoUser';")
   get revBrowserExecuteScript(tBrowserId, "document.form1.pwd.value = 'demoPassword';")
   get revBrowserExecuteScript(tBrowserId, "document.getElementById('submit').click();")
end mouseUp


I have made a modification of that code to get to the web page I want. It looks like the following:

Code: Select all

on mouseUp
   local tBrowserId
   
   put revBrowserOpen(the windowId of this stack, "http://www.petfinder.com/admin") into tBrowserId
   revBrowserSet tBrowserId, "rect", "20,0,400,400"
   if tBrowserId is not an integer then answer "Failed to open browser"
   wait 10 seconds
   -- populate fields
   get revBrowserExecuteScript(tBrowserId, "document.frm_login.username.value = 'myName';")
   get revBrowserExecuteScript(tBrowserId, "document.frm_login.password.value = 'myPassword';")
   
   --   get revBrowserExecuteScript(tBrowserId, "document.getElementById('submit').click();")
   --   get revBrowserExecuteScript(tBrowserId, "document.getElementByType('submit').click();")
   --   get revBrowserExecuteScript(tBrowserId, "document.getElementByTagName('sign_in').click();")
   --   get revBrowserExecuteScript(tBrowserId, "document.getElementByTabIndex('3').click();")
   --   get revBrowserExecuteScript(tBrowserId, "document.getElementByValue('GO !').click();")
   
   revBrowserClose tBrowserId
end mouseUp
What I can't seem to accomplish is the 'click'. Each of the lines that are commented out have been tried but I never get to the next page. As you can see I have been stabbing in the dark a bit. Since the button that I want to click does not seem to have an ID I can't make getElementById to work.

If I put break points at the line I want to test and at the revBrowserClose command I can see that the fields for user name and passwword get filled. I get no error messages when the test line executes but I do not advance to the next page. If I abort the script at the last break point I can manually press the 'Go !' button and get to where I want to be.

Do you have any ideas or suggestions?

I would greatly appreciate them.
Regards,
Larry

Re: Question for Andrew

Posted: Thu Jul 22, 2010 8:28 pm
by dickey
Hello Larry,

Apologies for the late reply I was on holidays in the US/Canada with the family. The closest I came to San Diego was 'Legoland', which was very cool indeed.

OK the critical lines:

Code: Select all

  get revBrowserExecuteScript(tBrowserId, "document.frm_login.username.value = 'myName';") -- no changes
  get revBrowserExecuteScript(tBrowserId, "document.frm_login.password.value = 'myPassword';") -- no changes
  -- Now to the problem bit. Either of these methods should work: 
  get revBrowserExecuteScript(tBrowserId, "document.forms["frm_login"].submit();") -- or alternatively
  get revBrowserExecuteScript(tBrowserId, "document.frm_login.submit();") 
Your particular example web page has multiple forms and therefore the javascript to submit the form is a little different from that used in my original example.

Let me know how you go.

Kind regards, Andrew

Re: Question for Andrew

Posted: Fri Jul 23, 2010 2:46 am
by lohill
Hi Andrew,
The closest I came to San Diego was 'Legoland', which was very cool indeed.
You 'missed be by that much'. Seriously, the next time you and the family get near San Diego, we would be happy to take you out to dinner.

It'll take me a day or two to test your suggestions but I'll let you know my results. I'll probably have moe questions by then too.

Regards,
Larry

Re: Question for Andrew

Posted: Fri Jul 23, 2010 6:51 pm
by lohill
Andrew,
-- Now to the problem bit. Either of these methods should work:
get revBrowserExecuteScript(tBrowserId, "document.forms["frm_login"].submit();") -- or alternatively
get revBrowserExecuteScript(tBrowserId, "document.frm_login.submit();")
Both of these work. I did have to change the double-quotes in the first one to single quotes. Here is what I have now:

Code: Select all

on mouseUp
   local tBrowserId
    put revBrowserOpen(the windowId of this stack, "http://www.petfinder.com/admin") into tBrowserId
   revBrowserSet tBrowserId, "rect", "20,0,400,400"
   if tBrowserId is not an integer then answer "Failed to open browser"
   wait 10 seconds
   -- populate fields
   get revBrowserExecuteScript(tBrowserId, "document.frm_login.username.value = 'username';")
   get revBrowserExecuteScript(tBrowserId, "document.frm_login.password.value = 'password';")
   
   get revBrowserExecuteScript(tBrowserId, "document.forms['frm_login'].submit();") 
   -- or alternatively
   --get revBrowserExecuteScript(tBrowserId, "document.frm_login.submit();") 
   
   -- Other example scripts I have tested
   --get revBrowserExecuteScript(tBrowserId,"alert('This is a message.');")   --This one works
   --put revBrowserExecuteScript(tBrowserId,"result = 1 + 1;") into myVar  --This works
   -- put revBrowserExecuteScript(tBrowserId,"result = document.frm_login.username.value;") into myVar  --This works
end mouseUp
This brings me to more questions. Is there something better than 'wait 10 seconds' to give revBrowser time to do its thing? Without that wait, the code gets you no where but it would be nice to put that wait into some kind of loop so that the minimum wait is used.

Also the revBrowserExecuteScript has a second argument which is Java script. Are there any good places to see other example of the types of scripts that can be used in that Java Script string. My example above has some that I got from the dictionary. Could one of those strings actually be multiple lines of Java code as long as they were separated by semi-colons?

While you were vacationing, I was trying to move ahead. In my project the web page shows a list of dogs. A click on one of a few places takes you to the detail on that dog. I would like my user to be able to click on a line in a datagrid and then have my program take the browser to the details on that dog.

When I view the source code of the web page that shows the list of dogs I can isolate the information for a particular dog. A piece of it looks like this:

Code: Select all

<tr valign="top">
            <td class="bodytext" bgcolor="#FFFFFF"><a href="/admin/admin.cgi?action=2&record=16833966">
              16833966
              </a></td>
Under program control I would like to 'click' that live spot and have revBrowser go to what turns out to be: http://www.petfinder.com/admin/admin.cg ... d=16833966

That's the kind of thing I'd like to learn how to do.

Thanks in advance for any suggestions,
Kind regards,
Larry

Re: Question for Andrew

Posted: Sat Jul 24, 2010 9:45 am
by Mark
Hi Larry,

Instead of putting everything in 1 script, you could put the part before the wait into the mouseUp handler and the part after the wai command into a browserNavigateComplete handler.

Best regards,

Mark

Re: Question for Andrew

Posted: Sat Jul 24, 2010 10:31 pm
by lohill
Thanks Mark,
Instead of putting everything in 1 script, you could put the part before the wait into the mouseUp handler and the part after the wai command into a browserNavigateComplete handler.
Could the test be kept in the same script it there was a global variable gBrowserBusy and setting it to true in an 'on BrowserBeforeNavigate' script and setting it to false in a 'on BrowserNavigateComplete' script. Would this allow you to put a repeat loop in your single script like

Code: Select all

   repeat
      if gBrowserBusy is false then exit repeat
   end repeat
Regards,
Larry

Re: Question for Andrew

Posted: Sat Jul 24, 2010 11:21 pm
by Mark
Hi Larry,

You don't want to keep it in the same handler. You want to split it up. Really.

Best,

Mark

Re: Question for Andrew

Posted: Mon May 30, 2011 3:21 pm
by Fjord
Hi, all.
The above post was very useful to me, as I'm trying to use a form to download a file from a financial site. The last form has no ID tag for the input fields so I'm using code like

Code: Select all

  get revBrowserExecuteScript(tBrowserId, "document.forms['monform'].elements['CODE'].value = 'GB00B10FHZ32';")
 
But:
1) how do I get a specific radio btn to be clicked? the HTML code looks like

Code: Select all

<li><input type="radio" class="check" name="MARCHE" value="EURSTX"  />ESTX50 EUR P</li>
<li><input type="radio" class="check" name="MARCHE" value="1008"  />Obligations</li>
<li><input type="radio" class="check" name="MARCHE" value="LISTE"  />Valeurs de mes listes</li>
			
the following doesn't work:

Code: Select all

get revBrowserExecuteScript(tBrowserId, "document.forms['monform'].elements['MARCHE'].value='LISTE';")
   
2) under the debugger, I let my code fill some fields then I manually click the "Download" btn and the file appears in the browser window. OK, but doing it by code below does'nt seem to submit the form:

Code: Select all

get revBrowserExecuteScript(tBrowserId, "document.forms['monform'].submit();")
3) how can I get the downloaded data into a LiveCode container?

Thanks for any help!