Sign in to follow this  
Followers 0
shreeks

How to automate button click in a URL which has no 'Control ID'?

7 posts in this topic

Hi,

Though I’ve found posts/threads which are pretty similar to my issue but this is a little different case.

I’ve to automate the process of clicking a button which is present in a HTML page. I couldn’t track down the ‘ControlID’ in the ‘AutoIt v3 Window Info’.

Attached with this post is my HTML source.To brief a little, the HTML page has to be opened automatically and the button(I’m not sure whether it’s a button/image) “Pentaho User Console Login” has to be clicked automatically. I couldn't attach the snapshot of my HTML page due to size limit. I can send you if you are interested. Please drop you mail ID in case if you want to.

Kindly, help me out in this regard. Thanks in advance.

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Pentaho User Console - Login</title>
<style type="text/css"> 
<!--
body,td,th {
    color: #000000;
}
body {
    background-color: #FFFFFF;
    margin: 0px;
}
p {
    margin: 0px;
    padding: 0px;
}
A:link,A:visited,A:active {
    color: #7e932f;
    text-decoration: underline;
}
A:hover {
    color: #ca6333;
    text-decoration: underline;
}
.login-banner {
    background-image: url(/pentaho-style/images/login/start_banner.png);
    background-repeat: repeat-x;
    padding: 90px 0px 0px 0px;
}
.lrg_box_top {
    background-image: url(/pentaho-style/images/login/start_lrg_box_top.png);
    background-repeat: no-repeat;
    height: 85px;
    text-align: center;
    vertical-align: bottom;
}
.lrg_box_bottom {
    background-image: url(/pentaho-style/images/login/start_lrg_box_bottom.png)
        ;
    background-repeat: no-repeat;
    background-position: bottom;
    padding: 0px 0px 25px 0px;
}
.sm_box_top {
    background-image: url(/pentaho-style/images/login/start_sm_box_top.png);
    background-repeat: no-repeat;
    text-align: center;
    vertical-align: bottom;
    font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
    font-size: 1.2em;
    color: #7e932f;
    font-weight: 300;
    text-align: left;
    padding: 10px 0px 0px 18px;
    width: 270px;
    cursor: pointer;
}
.sm_box_bottom {
    background-image: url(/pentaho-style/images/login/start_sm_box_bottom.png);
    background-repeat: no-repeat;
    background-position: bottom left;
    font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
    font-size: .85em;
    color: #000000;
    text-align: left;
    vertical-align: top;
    padding: 10px 20px 16px 18px;
    width: 270px;
    cursor: pointer;
}
.start_login_title {
    font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
    font-size: 1.2em;
    color: #7e932f;
    font-weight: 300;
    text-align: left;
    padding: 18px 0px 0px 18px;
}
.start_content {
    font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
    font-size: .85em;
    color: #000000;
    text-align: left;
    vertical-align: bottom;
    padding: 10px 0px 0px 18px;
}
.btn_login_box {
    background-image: url(/pentaho-style/images/login/start_btn_login.png);
    width: 204px;
    height: 69px;
    text-align: center;
    margin: 18px;
    cursor: pointer;
}
.btn_login_box-hover {
    background-image:
        url(/pentaho-style/images/login/start_btn_login_hover.png);
    width: 204px;
    height: 69px;
    text-align: center;
    margin: 18px;
    cursor: pointer;
}
.btn_login_title {
    font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
    font-size: 1em;
    font-weight: bold;
    text-align: center;
    vertical-align: bottom;
    height: 28px;
}
.btn_login_text {
    font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
    font-size: 1.5em;
    font-weight: 300;
    text-align: center;
    vertical-align: top;
    height: 41px;
}
.start_footer {
    background-image: url(/pentaho-style/images/login/start_footer_bg.png);
    background-repeat: repeat-x;
    background-position: top;
    padding: 20px 0px 0px 0px;
    margin-top: 20px;
    vertical-align: bottom;
}
.footer_txt {
    width: 564px;
    font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
    font-size: .7em;
    text-align: left;
    vertical-align: top;
}
.button {
    font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
    font-size: 1em;
    font-weight: 300;
}
.button .button_left {
    background-image: url('/pentaho-style/images/login/button_left.png');
}
.button .button_middle {
    background-image: url('/pentaho-style/images/login/button_middle.png');
    background-repeat: repeat-x;
    white-space: nowrap;
    line-height: 24px;
    vertical-align: top;
}
.button .button_right {
    background-image: url('/pentaho-style/images/login/button_right.png');
}
.button_over {
    font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
    font-size: 1em;
    font-weight: 300;
}
.button_over .button_left {
    background-image: url('/pentaho-style/images/login/button_left_over.png');
}
.button_over .button_middle {
    background-image: url('/pentaho-style/images/login/button_middle_over.png')
        ;
    background-repeat: repeat-x;
    white-space: nowrap;
    line-height: 24px;
    vertical-align: top;
}
.button_over .button_right {
    background-image: url('/pentaho-style/images/login/button_right_over.png');
}
-->
</style>
<meta name="gwt:property" content="locale=en_US">
<link rel="shortcut icon" href="/pentaho-style/favicon.ico" />
<link href="/pentaho-style/styles-new.css" rel="stylesheet"
    type="text/css" />
    <script type="text/javascript">
    function logout(){
      var req = null;
      if (window.XMLHttpRequest){
        req = new XMLHttpRequest();
      } else if(windw.ActiveXObject){
        req = new ActiveXObject("Microsoft.XMLHTTP");
      }
      var responseHandler = function(){
       if(req.readyState == 4){
         if(req.status == 200){
           openLoginDialog('http://localhost:8080/pentaho/Home');
          } else {
            window.location.href = window.location.href; 
          }
        }
      }
      if(req == null){
        document.location="Logout";
      } else {
        req.onreadystatechange = responseHandler;
        req.open("GET","Logout",true);
        req.send("");
      }
    }
  </script>
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0"
    class="login-banner">
    <tr>
        <td align="center" bordercolor="0"><!--Begin First Box Row -->
        <table width="564" border="0" cellspacing="0" cellpadding="0"
            style="margin-bottom: 22px;" align="center">
            <tr>
                <td class="lrg_box_top"><a href="http://www.pentaho.com"
                    target="_blank"><img
                    src="/pentaho-style/images/login/start_logo.png"
                    alt="Pentaho Corporation" width="210" height="62" border="0" /></a></td>
            </tr>
            <tr>
                <td class="lrg_box_bottom">
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                        <td colspan="2" class="start_login_title">Welcome to the
                        Pentaho User Console</td>
                    </tr>
                    <tr>
                        <td class="start_content">
                        <p>The Pentaho User Console provides access to powerful Business 
                        Intelligence (BI) capabilities found in the Pentaho BI Suite. 
                        Login for access to your reports, analysis views and dashboards.</p>
                        </td>
                        <td><!--Begin Login Button -->
                        <table class="btn_login_box" border="0" cellspacing="0"
              cellpadding="0"
              onmouseover="this.className='btn_login_box-hover'"
              onmouseout="this.className='btn_login_box'"
              onblur="this.className='btn_login_box'"
              onclick="this.className='btn_login_box';openLoginDialog('http://localhost:8080/pentaho/Home')">
              <tr>
                <td class="btn_login_title">Pentaho User Console</td>
              </tr>
              <tr>
                <td class="btn_login_text">Login</td>
              </tr>
            </table>
                        <!--End Login Button --></td>
                    </tr>
                </table>
                </td>
            </tr>
        </table>
        <!--End First Box Row --></td>
    </tr>
    <!--Begin Footer -->
    <tr>
        <td align="center" class="start_footer">
        <table width="564" border="0" cellspacing="0" cellpadding="0"
            style="margin-bottom: 22px;" align="center">
            <tr>
                <td class="footer_txt">© 2005-2011 Pentaho Corporation.
                All rights reserved.</td>
            </tr>
        </table>
</body>
<script language='javascript'
    src='mantleLogin/mantleLogin.nocache.js'></script>
</html>


Learning is Lifelong!

Share this post


Link to post
Share on other sites



shreeks,

I dunno whether this will do the trick, but have you considered using MouseMove() and MouseClick()?

4Eyes

Share this post


Link to post
Share on other sites

shreeks,

I dunno whether this will do the trick, but have you considered using MouseMove() and MouseClick()?

4Eyes

Hi 4Eyes,

Thanks for your reply.

send("#r")
WinWaitActive("Run")
send("http://localhost:8080/pentaho{Enter}")
MouseClick("left",788,387,1)
MouseClick("left",648,359,1)

The above code works fine. The script invokes ‘Run’ prompt, types the URL in IE’s address bar and finally the mouse clicks the ‘Log In’ present in the desired (x,y). This code works fine in 17 inch Lenovo monitors. But this code might not be compatible with other monitor sizes. I need to write a code that should be compatible irrespective of monitor sizes? Is there any other way to write a code or accomplish my above said task(Refer the very 1st post of this thread)?


Learning is Lifelong!

Share this post


Link to post
Share on other sites

shreeks,

I don't do html, but does the 'button' move in relation to the size of the browser window? If so you're in trouble for the mouse move technique otherwise you should be fine. You can test it simply by changing the rez on your current system. 17" rez is prob 1024x768 or 1280x1024 but will support 800x600.

4Eyes

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Seems to me the login button links to "http://localhost:8080/pentaho/Home"

ShellExecute('http://localhost:8080/pentaho/Home');Same as Run.

If this is not the case then you could search for a specific colour in the logo using PixelSearch and use the coordinates as a reference.

Opt('WinTitleMatchMode', 2)
WinActivate('Pentaho User Console - Login')
WinWaitActive('Pentaho User Console - Login')
$iPos = WinGetPos('Pentaho User Console - Login')
$iPos = PixelSearch($iPos[0], $iPos[1], $iPos[2] + $iPos[0], $iPos[3] + $iPos[1], 0x7E932F, 1)
If Not @error Then MouseMove($iPos[0], $iPos[1])
Edited by BitByteBit

Share this post


Link to post
Share on other sites

Seems to me the login button links to "http://localhost:8080/pentaho/Home"

ShellExecute('http://localhost:8080/pentaho/Home');Same as Run.

If this is not the case then you could search for a specific colour in the logo using PixelSearch and use the coordinates as a reference.

Opt('WinTitleMatchMode', 2)
WinActivate('Pentaho User Console - Login')
WinWaitActive('Pentaho User Console - Login')
$iPos = WinGetPos('Pentaho User Console - Login')
$iPos = PixelSearch($iPos[0], $iPos[1], $iPos[2] + $iPos[0], $iPos[3] + $iPos[1], 0x7E932F, 1)
If Not @error Then MouseMove($iPos[0], $iPos[1])

Hi BitByteBit,

Thanks a lot. It has helped me out immensely. I had to just change the color code which you mentioned to automate the procedure of my interest. Thanks again.


Learning is Lifelong!

Share this post


Link to post
Share on other sites

Hi,

Below is the issue that I’m facing now.

PFA snapshot with this post for reference.

The task is to automate the click of “Open” button(Button/Icon? Not sure) (Refer snapshot). I don’t want to capture the (x,y)’s of the button and then automate the click process since it may/may not work with other screen resolutions as well. Secondly, except the ‘ControlClick Coords’ (under ‘Control’ tab in ‘AutoIt v3 Window Info’) nothing gets changed. Likewise, ‘Position’ and ‘Color’ (under ‘Mouse’ tab in ‘AutoIt v3 Window Info’).

Is there any way/procedure to automate the click of “Open” button? Kindly help me with sample code if you have. If you need more details please feel free to contact at shreeks@ymail.com

Thanks. For further reference below is the HTML code of the page in which the “Open” button(Button/Icon? Not sure) is present.

<html>
    <head>
        <title>Pentaho User Console</title>
        <meta name="gwt:property" content="locale=en_US">
        <link rel="shortcut icon" href="/pentaho-style/favicon.ico" />
        <link rel='stylesheet' href='mantle/MantleStyle.css'/>
        <link rel="stylesheet" href="content/data-access/resources/gwt/datasourceEditorDialog.css">
    <script type="text/javascript" src="mantle/nativeScripts.js"></script>
    <script type="text/javascript">
      if(window.opener && window.opener.reportWindowOpened != undefined){
        window.opener.reportWindowOpened();
      }
    var dataAccessAvailable = false; //Used by child iframes to tell if data access is available.
    /* this function is called by the gwt code when initing, if the user has permission */
    function initDataAccess(hasAccess) {
      dataAccessAvailable = hasAccess;
      if(!hasAccess){
        return;
      }
      if(typeof(addMenuItem) == "undefined"){
        setTimeout("initDataAccess("+hasAccess+")", 1000);
        return;
      } else {
        addMenuItem("manageDatasourcesEllipsis","manage_content_menu", "ManageDatasourcesCommand");
        addMenuItem("newDatasource","new_menu", "AddDatasourceCommand");
      }
    }
    var datasourceEditorCallback = {
      onfinish : function(val, transport) {
      },
      onerror : function(val) {
        alert('error:' + val);
      },
      onCancel : function() {
      },
      onReady : function() {
      }
    }
    // This allows content panels to have PUC create new datasources. The iframe requesting
    // the new datasource must have a function "openDatasourceEditorCallback" on it's window scope
    // to be notified of the successful creation of the datasource.
    function openDatasourceEditorIFrameProxy(windowReference){
        var callbackHelper = function(bool, transport){
            windowReference.openDatasourceEditorCallback(bool, transport);
        }
        openDatasourceEditor(new function(){
        this.onerror = function(err){
          alert(err);
        }
        this.onCancel = function(){
        }
        this.onReady = function(){
        }
        this.onfinish = function(bool, transport){
          callbackHelper(bool, transport);
        }
      });
    }
    </script>
    </head>
    <body oncontextmenu="return false;">
    <div id="loading">
            <div class="loading-indicator">
                <img src="mantle/large-loading.gif" width="32" height="32"/>Pentaho User Console is Loading...<a href="http://www.pentaho.com"></a><br/>
                <span id="loading-msg">Please Wait</span>
            </div>
    </div>
    <!-- OPTIONAL: include this if you want history support -->
    <iframe id="__gwt_historyFrame" style="width:0px;height:0px;border:0;display:none"></iframe>
    </body>
    <script language='javascript' src='mantle/mantle.nocache.js'></script>
    <script language='javascript' src='content/data-access/resources/gwt/DatasourceEditor.nocache.js'></script>
</html>


Learning is Lifelong!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0