joe chesak
2010-Jun-15 10:17 UTC
[Mechanize-users] following a javascript link that unhides a field ... quick workaround?
I am using Mechanize for the first time, and have gone through a login page and a couple of links. But I am now attempting to click a javascript link. The link unhides a div that has three fields in it. And Mechanize throws an error when I hit this javascript link. Here is html of the javascript link.... <a id="_ctl20_hlAvgrensRevisor" class="AdvanceSearchLink" onclick="if ( document.getElementById(''_ctl20_hiddenRevisor'').value == ''none'') { document.getElementById(''_ctl20_DivRevisor'').style[''display''] = ''''; document.getElementById(''_ctl20_hiddenRevisor'').value = ''''; } else { document.getElementById(''_ctl20_DivRevisor'').style[''display''] = ''none''; document.getElementById(''_ctl20_hiddenRevisor'').value = ''none''; }" href="javascript:;">Avgrens p? Revisor/Regnskapsf?rer</a><input name="_ctl20:hiddenRevisor" type="hidden" id="_ctl20_hiddenRevisor" value="none" /> ...which shows up like this in Mechanize.... #<Mechanize::Page::Link "Avgrens p? Revisor/Regnskapsf?rer" "javascript:;"> ...and then I click it like this and get the following error...>> agent.page.link_with(:text => /Avgrens p? Revisor.*/).clickERROR Mechanize::UnsupportedSchemeError: Mechanize::UnsupportedSchemeError from /Users/joe/.gem/ruby/1.8/gems/mechanize-1.0.0/lib/mechanize.rb:166:in `initialize'' from /Users/joe/.gem/ruby/1.8/gems/mechanize-1.0.0/lib/mechanize/chain/uri_resolver.rb:39:in `call'' from /Users/joe/.gem/ruby/1.8/gems/mechanize-1.0.0/lib/mechanize/chain/uri_resolver.rb:39:in `handle'' from /Users/joe/.gem/ruby/1.8/gems/mechanize-1.0.0/lib/mechanize/chain.rb:24:in `handle'' from /Users/joe/.gem/ruby/1.8/gems/mechanize-1.0.0/lib/mechanize.rb:509:in `fetch_page'' from /Users/joe/.gem/ruby/1.8/gems/mechanize-1.0.0/lib/mechanize.rb:259:in `get'' from /Users/joe/.gem/ruby/1.8/gems/mechanize-1.0.0/lib/mechanize.rb:315:in `click'' from /Users/joe/.gem/ruby/1.8/gems/mechanize-1.0.0/lib/mechanize/page/link.rb:44:in `click'' from (irb):92 from :0 ...Oh, and here''s what the hidden div looks like... <div id="_ctl20_DivRevisor" style="display: none; width: 100%"> <table id="TableRev" cellspacing="0" cellpadding="1" width="100%" border="0"> <tbody> <tr> <td nowrap> Organisasjonsnummer revisor:</td> <td width="100%"> <input name="_ctl20:txtRevisorOrgnr" type="text" maxlength="9" id="_ctl20_txtRevisorOrgnr" class="stor" /> <span controltovalidate="_ctl20_txtRevisorOrgnr" errormessage="Avgrens p? revisor orgnr; m? v?re 9 siffer uten mellomrom" display="Dynamic" id="_ctl20_rvOrgnr" evaluationfunction="RegularExpressionValidatorEvaluateIsValid" validationexpression="\d{9}" style="color:Red;display:none;">M? v?re 9 siffer uten mellomrom!</span> </td> </tr> <tr> <td nowrap> Organisasjonsnummer regnskapsf?rer:</td> <td width="100%"> <input name="_ctl20:txtRegnskForerOrgnr" type="text" maxlength="9" id="_ctl20_txtRegnskForerOrgnr" class="stor" /> <span controltovalidate="_ctl20_txtRegnskForerOrgnr" errormessage="Avgrens p? regnskapsf?rer orgnr; m? v?re 9 siffer uten mellomrom" display="Dynamic" id="_ctl20_rvOrgnrRegnskapsforer" evaluationfunction="RegularExpressionValidatorEvaluateIsValid" validationexpression="\d{9}" style="color:Red;display:none;">M? v?re 9 siffer uten mellomrom!</span> </td> </tr> <tr> <td> Navn regnskapsf?rer:</td> <td> <input name="_ctl20:txtRegnskForer" type="text" id="_ctl20_txtRegnskForer" class="stor" /> firmanavn eller personnavn (etternavn fornavn mellomnavn) </td> </tr> </tbody> </table> </div> ... So it looks like everything I need should be here. I have to believe that there must be manual way for me to ''give'' Mechanize what it needs to be able to build it''s internal model with these three fields. How should I proceed? Joe -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/mechanize-users/attachments/20100615/77aeba92/attachment-0001.html>
jeremywoertink at gmail.com
2010-Jun-15 14:48 UTC
[Mechanize-users] following a javascript link that unhides a field ... quick workaround?
Mechanize can''t parse JavaScript. Look into using Harmony. Oh, and good luck! On Jun 15, 2010, at 3:17 AM, joe chesak <mechanize at chesak.com> wrote:> I am using Mechanize for the first time, and have gone through a > login page and a couple of links. But I am now attempting to click > a javascript link. The link unhides a div that has three fields in > it. And Mechanize throws an error when I hit this javascript link. > > > Here is html of the javascript link.... > > > <a id="_ctl20_hlAvgrensRevisor" class="AdvanceSearchLink" > onclick="if ( document.getElementById(''_ctl20_hiddenRevisor'').value > == ''none'') { document.getElementById(''_ctl20_DivRevisor'').style > [''display''] = ''''; document.getElementById > (''_ctl20_hiddenRevisor'').value = ''''; } else { document.getElementById > (''_ctl20_DivRevisor'').style[''display''] = ''none''; > document.getElementById(''_ctl20_hiddenRevisor'').value = ''none''; }" > href="javascript:;">Avgrens p? Revisor/Regnskapsf?rer</a><input name > ="_ctl20:hiddenRevisor" type="hidden" id="_ctl20_hiddenRevisor" valu > e="none" /> > > > ...which shows up like this in Mechanize.... > > > #<Mechanize::Page::Link "Avgrens p? Revisor/Regnskapsf?rer" "javascr > ipt:;"> > > > ...and then I click it like this and get the following error... > > > >> agent.page.link_with(:text => /Avgrens p? Revisor.*/).click > > ERROR > Mechanize::UnsupportedSchemeError: Mechanize::UnsupportedSchemeError > from /Users/joe/.gem/ruby/1.8/gems/mechanize-1.0.0/lib/ > mechanize.rb:166:in `initialize'' > from /Users/joe/.gem/ruby/1.8/gems/mechanize-1.0.0/lib/mechanize/ > chain/uri_resolver.rb:39:in `call'' > from /Users/joe/.gem/ruby/1.8/gems/mechanize-1.0.0/lib/mechanize/ > chain/uri_resolver.rb:39:in `handle'' > from /Users/joe/.gem/ruby/1.8/gems/mechanize-1.0.0/lib/mechanize/ > chain.rb:24:in `handle'' > from /Users/joe/.gem/ruby/1.8/gems/mechanize-1.0.0/lib/ > mechanize.rb:509:in `fetch_page'' > from /Users/joe/.gem/ruby/1.8/gems/mechanize-1.0.0/lib/ > mechanize.rb:259:in `get'' > from /Users/joe/.gem/ruby/1.8/gems/mechanize-1.0.0/lib/ > mechanize.rb:315:in `click'' > from /Users/joe/.gem/ruby/1.8/gems/mechanize-1.0.0/lib/mechanize/ > page/link.rb:44:in `click'' > from (irb):92 > from :0 > > > ...Oh, and here''s what the hidden div looks like... > > > <div id="_ctl20_DivRevisor" style="display: none; > width: 100%"> > <table id="TableRev" cellspacing="0" > cellpadding="1" width="100%" border="0"> > <tbody> > <tr> > <td nowrap> > Organisasjonsnummer revisor:</td> > > <td width="100%"> > <input > name="_ctl20:txtRevisorOrgnr" type="text" maxlength="9" > id="_ctl20_txtRevisorOrgnr" class="stor" /> > <span > controltovalidate="_ctl20_txtRevisorOrgnr" errormessage="Avgrens p? > revisor orgnr; m? v?re 9 siffer uten mellomrom" display="Dynamic" id > ="_ctl20_rvOrgnr" evaluationfunction="RegularExpressionValidatorEval > uateIsValid" validationexpression="\d{9}" style="color:Red;display:n > one;">M? v?re 9 siffer uten mellomrom!</span> > </td> > </tr> > <tr> > <td nowrap> > Organisasjonsnummer regnskapsf?r > er:</td> > > <td width="100%"> > <input > name="_ctl20:txtRegnskForerOrgnr" type="text" maxlength="9" > id="_ctl20_txtRegnskForerOrgnr" class="stor" /> > <span > controltovalidate="_ctl20_txtRegnskForerOrgnr" errormessage="Avgrens > p? regnskapsf?rer orgnr; m? v?re 9 siffer uten mellomrom" > display="Dynamic" id="_ctl20_rvOrgnrRegnskapsforer" evaluationfuncti > on="RegularExpressionValidatorEvaluateIsValid" validationexpression= > "\d{9}" style="color:Red;display:none;">M? v?re 9 siffer uten mellom > rom!</span> > </td> > </tr> > <tr> > <td> > Navn regnskapsf?rer:</td> > > <td> > <input > name="_ctl20:txtRegnskForer" type="text" id="_ctl20_txtRegnskForer" > class="stor" /> firmanavn > eller personnavn (etternavn > fornavn mellomnavn) > </td> > </tr> > </tbody> > </table> > </div> > > > ... So it looks like everything I need should be here. I have to > believe that there must be manual way for me to ''give'' Mechanize > what it needs to be able to build it''s internal model with these > three fields. How should I proceed? > > Joe > _______________________________________________ > Mechanize-users mailing list > Mechanize-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/mechanize-users