[Wtr-general] Question: Javascript/CSS onClick?

Paul Rogers paul.rogers at shaw.ca
Wed Aug 3 11:36:28 EDT 2005


a <td> should have a click method, so if you can figure out its index you can do

ie.table(:index,t)[row][col].click

You'll have to fixure out the row and col values and the value for t

It would be better if you can get an id added to that cell

Paul

----- Original Message -----
From: dnjohannes at gmail.com
Date: Wednesday, August 3, 2005 9:30 am
Subject: [Wtr-general] Question: Javascript/CSS onClick?

> All,
> 
> Forgive me if I am asking an obvious question, this is my second
> attempt to post this and get some sort of answer to my issue.  Now I
> personally have a problem. I need to automate the login for further
> testing, but I cannot figure out how to access the 'Log In' button
> which has been defined in the Cascading Style Sheets.  Any help would
> be appreciated. I have included HTML, CSS, and Javascript code.
> 
> Dave
> 
> 
> -=-=- getHTML -=-=-
> 
> irb(main):072:0> ie.frame("main").frame("frmLogin").getHTML
> => "\r\n<BODY language=javascript class=normal 
> oncontextmenu=\"return false\"
> bottomMargin=0 leftMargin=0 background=../../graphics/side_1.gif 
> topMargin=0 o
> nload=isError(); rightMargin=0><FORM onkeypress=checkKey(); 
> id=frmLogin name=f
> rmLogin action=verifyLogin.asp method=post target=_self>\r\n<TABLE 
> cellSpacing=0 cellPadding=0 width=\"100%\" 
> border=0>\r\n<TBODY>\r\n<TR>\r\n<TD class=text
> o style=\"PADDING-RIGHT: 5px; PADDING-LEFT: 5px; PADDING-BOTTOM: 
> 5px; PADDING-
> TOP: 5px\">user: </TD>\r\n<TD style=\"PADDING-RIGHT: 2px; PADDING-
> LEFT: 2px; P
> ADDING-BOTTOM: 2px; PADDING-TOP: 2px\"><INPUT class=texto id=user 
> size=12 name
> =user width=\"100%\"> </TD></TR>\r\n<TR>\r\n<TD class=texto 
> style=\"PADDING-RI
> GHT: 5px; PADDING-LEFT: 5px; PADDING-BOTTOM: 5px; PADDING-TOP: 
> 5px\">password:</TD>\r\n<TD style=\"PADDING-RIGHT: 2px; PADDING-
> LEFT: 2px; PADDING-BOTTOM: 2p
> x; PADDING-TOP: 2px\"><INPUT class=texto id=pass type=password 
> size=12 value=\
> "\" name=pass width=\"100%\"> </TD></TR>\r\n<TR>\r\n<TD 
> align=middle colSpan=2
> >\r\n<TABLE height=20 cellSpacing=0 cellPadding=0 
> border=0>\r\n<TBODY>\r\n<TR>\r\n<TD class=loginOnOut 
> onmouseover=\"javascript:this.className='loginOnOver'\" 
> style=\"WIDTH: 60px; HEIGHT: 22px\" 
> onclick=javascript:verifyUser(); onmous
> eout=\"javascript:this.className='loginOnOut'\">    </TD></TR><
> /TBODY></TABLE></TD></TR></TBODY></TABLE></FORM></BODY>"
> 
> 
> 
> -=-=- Form/Table for login data -=-=-
> 
> <!-- START FORM -->
> <form onkeypress="checkKey();" id="frmLogin" name="frmLogin"
> action="verifyLogin.asp" method="post" target="_self">
> <table width="100%" border="0" cellpadding="0" cellspacing="0">
>  <!-- FIRST ROW -->
>  <tr>
>    <td class="texto" style="padding:5px;">
>      user:
>    </td>
>    <td style="padding:2px; ">
>      <input name="user" type="text" class="texto" id="user" value=""
> size="12" width="100%">
>    </td>
>  </tr>
>  <!-- SECOND ROW -->
>  <tr>
>    <td class="texto" style="padding:5px;">
>      password:
>    </td>
>    <td style="padding:2px; ">
>      <input name="pass" type="password" class="texto" id="pass"
> value="" size="12" width="100%">
>    </td>
>  </tr>
>  <!-- THIRD ROW -->
>  <tr>
>    <td colspan="2" align="center">
>      <table border="0" cellpadding="0" cellspacing="0" height="20">
>        <tr>
>          <td class="loginOnOut" onclick="javascript:verifyUser();"
>          onmouseover="javascript:this.className='loginOnOver'"
>          onmouseout="javascript:this.className='loginOnOut'"
>          style="height:22px; width:60px;">   
>          </td>
>        </tr>
>      </table>
>    </td>
>  </tr>
> </table>
> </form>
> <!-- END FORM -->
> 
> 
> 
> -=-=- Javascript -=-=-
> 
> <script language="javascript">
> 
>  function isError(){
>    if (-1 > 0){
>      if (-1 == 1){
>        alert("The Username is invalid or the User does not exist!");
>        frmLogin.user.focus();
>      } else if (-1 == 2){
>        alert("The Password is invalid,\rplease, try again.");
>        frmLogin.user.focus();
>      }
>    }
>  }
> 
> 
>  function verifyUser(){
>    if (frmLogin.user.value == ""){
>      alert("You must enter a Username!");
>      frmLogin.user.focus();
>    } else if (frmLogin.user.value.length < 4){
>      alert("The Username must be at least 4 characters long.");
>      frmLogin.user.focus();
>    } else if (frmLogin.pass.value == ""){
>      alert("You must enter a Password!");
>      frmLogin.pass.focus();
>    } else if ((frmLogin.pass.value.length < 4) ||
> (frmLogin.pass.value.length > 10)){
>      alert("The Password must be at least 4 characters and a maximum
> of 10 character.");
>      frmLogin.pass.focus();
>    } else {
>      frmLogin.submit();
>    }
>  }	
> 
> 
>  function checkKey(){
>    if (window.event.keyCode == 13){
>      verifyUser();
>    }
>  }
> 
> </script>
> 
> 
> 
> -=-=- CSS -=-=-
> 
> td.loginOnOver{
>       background-image: url(../graphics/logindown.jpg);
>       height: 22px;
>       width: 60px;
>       cursor: hand;
> }
> 
> td.loginOnOut{
>       background-image: url(../graphics/loginup.jpg);
>       height: 22px;
>       width: 60px;
> }
> 
> 
> 
> -=-=- Test code to login (minus clicking the 'Log In' button) -=-=-
> 
> require 'test/unit'
> #variables
> testSite = "http://192.168.5.5/login/"
> #open the IE browser
> ie = IE.new
> 
> ie.goto(testSite)
> 
> puts "Entering user ID"
> ie.frame("main").frame("frmLogin").text_field(:name,"user").set("testeracct")
> puts "Entering user password"
> ie.frame("main").frame("frmLogin").text_field(:name,"pass").set("123456")
> puts "Clicking Log In button"
> 
> _______________________________________________
> Wtr-general mailing list
> Wtr-general at rubyforge.org
> http://rubyforge.org/mailman/listinfo/wtr-general
> 




More information about the Wtr-general mailing list