<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: automation code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Fri, 25 Jul 2008 16:16:33 GMT</pubDate>
    <description>DZone Snippets: automation code</description>
    <item>
      <title>Submit Form programmatically from PHP using JavaScript</title>
      <link>http://snippets.dzone.com/posts/show/5154</link>
      <description>It&#180;s something quite easy but may help a newby (as I&#180;m now) in the future. &lt;br /&gt;This is a simple function in PHP to insert a JavaScript sentence which will do the same action as if the user would be pressing the Submit Button.&lt;br /&gt;It can be used to use any control as a Submit Button or in case you make a form you need to send without interaction from the user.&lt;br /&gt;the $FormName must be the name specified in the Form tag (i.e.: &lt;form action="MyActionURL" method="post" enctype="application/x-www-form-urlencoded" name="MyFormName"&gt;), if you didn&#180;t specified any, you must now :)&lt;br /&gt;Lastly, just a tip regarding a trouble I had and may be you case too... if you have a form with all hidden fields, it won&#180;t work, you have to have at least something echoed inside the form, just a letter can help, anyway, as it will redirect to the action URL, it should not be a problem as the form will disappear.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;function SubmitForm($FormName)&lt;br /&gt;//JavaScript function to submit a form programmatically&lt;br /&gt;//$FormName must be form&#180;s name (as specified in the opening form tag)&lt;br /&gt;{&lt;br /&gt;	echo '&lt;script language="javascript"&gt;document.'.$FormName.'.submit()&lt;/script&gt;';&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 19 Feb 2008 20:23:28 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5154</guid>
      <author>dneuma (Daniel Neumann)</author>
    </item>
    <item>
      <title>Browser automation using perl LWP</title>
      <link>http://snippets.dzone.com/posts/show/4587</link>
      <description>// This is a sample code used to measure reports response times on a OAS application.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;#&lt;br /&gt;# LWP connection to the Datamart Portal&lt;br /&gt;# Timing of the main reports&lt;br /&gt;#&lt;br /&gt;&lt;br /&gt;use strict;&lt;br /&gt;require LWP::UserAgent;&lt;br /&gt;&lt;br /&gt;my $ua = LWP::UserAgent-&gt;new;&lt;br /&gt;&lt;br /&gt;sub isodate() {&lt;br /&gt;        my ($day, $mon, $year, $hour, $min, $sec) = (localtime)[3, 4, 5, 2, 1, 0];&lt;br /&gt;        $mon++; # 0-based index&lt;br /&gt;        $year = $year + 1900;&lt;br /&gt;        my $date = sprintf ("%04i-%02i-%02i %02i\:%02i\:%02i", $year, $mon, $day, $hour, $min, $sec);&lt;br /&gt;        return $date;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;sub datamart_login {&lt;br /&gt;        my ( $user, $pass ) = @_;&lt;br /&gt;        my $time_begin=time();&lt;br /&gt;        my $url='http://daprd:7782/portal/page?_pageid=37,134413,37_134422&amp;_dad=portal&amp;_schema=PORTAL';&lt;br /&gt;        my $req = HTTP::Request-&gt;new( GET =&gt; $url );&lt;br /&gt;        my $resp = $ua-&gt;request($req);&lt;br /&gt;        my $loginform = $resp-&gt;content ;&lt;br /&gt;        if ( $loginform !~ /Entrez votre nom utilisateur/ ) {&lt;br /&gt;                die isodate()." Failed to get the logon page of the Web Site\n";&lt;br /&gt;        } else {&lt;br /&gt;                my $locale="";&lt;br /&gt;                my ($v) = $loginform =~ /NAME=\"v\" value=\"(.+)\"/;&lt;br /&gt;                my ($site2pstoretoken) = $loginform =~ /NAME=\"site2pstoretoken\" value=\"(.+)\"/;&lt;br /&gt;                my ($submiturl) = $loginform =~ /form method=\"POST\" action=\"(.*?)\"/;&lt;br /&gt;                $resp = $ua-&gt;post( $submiturl,&lt;br /&gt;                   [&lt;br /&gt;                     ssousername =&gt; $user,&lt;br /&gt;                     password =&gt; $pass,&lt;br /&gt;                     v =&gt; $v,&lt;br /&gt;                     locale =&gt; $locale,&lt;br /&gt;                     site2pstoretoken =&gt; $site2pstoretoken&lt;br /&gt;                   ],&lt;br /&gt;                );&lt;br /&gt;                $resp = $ua-&gt;get($url);&lt;br /&gt;                $resp = $ua-&gt;get($url);&lt;br /&gt;                if ( $resp-&gt;content !~ /Crit..res de recherche/ ) {&lt;br /&gt;                        die isodate()." Failed to get the main page of Portal\n";&lt;br /&gt;                }&lt;br /&gt;        }&lt;br /&gt;        print join(";",isodate(),"Time to log on the Portal",time()-$time_begin,$url)."\n";&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;sub datamart_testurl {&lt;br /&gt;        my ($label,$url,$expected)=@_;&lt;br /&gt;        my $time_begin=time();&lt;br /&gt;        my $resp;&lt;br /&gt;        $resp = $ua-&gt;get($url);&lt;br /&gt;        $resp = $ua-&gt;get($url) if $resp-&gt;content !~ /$expected/;        # We try two times !&lt;br /&gt;        if ( $resp-&gt;content !~ /$expected/ ) {&lt;br /&gt;                print STDERR isodate()." Test Failed on $label. $expected not found in response.\n";&lt;br /&gt;                print STDERR $resp-&gt;as_string;&lt;br /&gt;        } else {&lt;br /&gt;                print join(";",isodate(),$label,time()-$time_begin,$url)."\n";&lt;br /&gt;        }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;$ua-&gt;timeout(1200);&lt;br /&gt;$ua-&gt;cookie_jar({});&lt;br /&gt;$ua-&gt;agent( 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)' );&lt;br /&gt;#push @{ $ua-&gt;requests_redirectable }, 'POST';&lt;br /&gt;&lt;br /&gt;# &gt;&gt;&gt;&gt; Main code here&lt;br /&gt;&lt;br /&gt;datamart_login("xxxx","xxxx");&lt;br /&gt;&lt;br /&gt;open FH,"/exploit/scripts/appli/check_datamart.ini" or die "Unable to open check_datamart.ini";&lt;br /&gt;while (&lt;FH&gt;) {&lt;br /&gt;        chomp();&lt;br /&gt;        my ($report,$expected,$url) = split /;/;&lt;br /&gt;        datamart_testurl($report,$url,$expected);&lt;br /&gt;}&lt;br /&gt;close FH;&lt;br /&gt;&lt;br /&gt;# &lt;&lt;&lt;&lt; Main code here&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 28 Sep 2007 11:48:47 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4587</guid>
      <author>bouffon69 (Sylvain Le Courtois)</author>
    </item>
    <item>
      <title>JavaScript: Programmatically Click the Form Submit Button</title>
      <link>http://snippets.dzone.com/posts/show/3633</link>
      <description>// Programmatically Click the Form Submit Button&lt;br /&gt;// by using the 'click()' method&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;  submitTags : function()&lt;br /&gt;  {&lt;br /&gt;    var btnSubmitTags = document.getElementById( TagsHelperConfig.FORM_TAGS_ENTRY_SUBMIT_BUTTON_ID );&lt;br /&gt;&lt;br /&gt;    // Programmatically click the submit button&lt;br /&gt;    btnSubmitTags.click();&lt;br /&gt;  }&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 06 Mar 2007 09:30:57 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3633</guid>
      <author>thitiv (Thiti V. Sintopchai)</author>
    </item>
    <item>
      <title>Mass conversion from word to HTML</title>
      <link>http://snippets.dzone.com/posts/show/416</link>
      <description>I got 1000 word files. Each contains 1 main image and some decorations.&lt;br /&gt;(This is actually a big book scanned into 1-file-per-page format)&lt;br /&gt;I need to extract all the images. What do I do?&lt;br /&gt;&lt;br /&gt;Python can do some automation using COM. (or something like that)&lt;br /&gt;&lt;code&gt;&lt;br /&gt;import pythoncom, win32com.client&lt;br /&gt;&lt;br /&gt;app = win32com.client.gencache.EnsureDispatch("Word.Application")&lt;br /&gt;&lt;br /&gt;doc = 'C:\\lang\\try\\bdham\\p1'&lt;br /&gt;app.Documents.Open(doc + '.doc')&lt;br /&gt;app.ActiveDocument.SaveAs(doc + '.html', FileFormat=win32com.client.constants.wdFormatHTML)&lt;br /&gt;app.ActiveDocument.Close()&lt;br /&gt;# now repeat with p2, p3, etc.&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Actually, I should put it in a loop. But this non-loop version&lt;br /&gt;is easier to read and remember.</description>
      <pubDate>Tue, 28 Jun 2005 00:02:06 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/416</guid>
      <author>korakot (Korakot Chaovavanich)</author>
    </item>
    <item>
      <title>IE Automation in Python</title>
      <link>http://snippets.dzone.com/posts/show/289</link>
      <description>I try to dump my data out of a website. But it block my python's urllib bot. I tried other pure python libray but without success. So, I try a quicker route using IE automation.&lt;br /&gt;For general automation you should try 'watsup'. For IE, there is PAMIE.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&gt;&gt;&gt; from cPAMIE import PAMIE&lt;br /&gt;&gt;&gt;&gt; ie = PAMIE()&lt;br /&gt;&gt;&gt;&gt; ie.Navigate('www.google.com')   # go to google&lt;br /&gt;&gt;&gt;&gt; ie.SetTextBox('Python','q',0)       # search for python&lt;br /&gt;&gt;&gt;&gt; ie.ClickButton('btnG')               # Go!&lt;br /&gt;&lt;br /&gt;&gt;&gt;&gt; src = ie.pageText()                 # here it is&lt;br /&gt;&gt;&gt;&gt; cookie = ie.GetCookie()          # Ok, cookie is yummy&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;PAMIE is actually aimed for more of the testing work.&lt;br /&gt;But in this case it serves me fine.&lt;br /&gt;http://pamie.sourceforge.net/</description>
      <pubDate>Sun, 15 May 2005 15:12:04 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/289</guid>
      <author>korakot (Korakot Chaovavanich)</author>
    </item>
  </channel>
</rss>
