dcsimg
Results 1 to 9 of 9

Thread: VBA clicking Onclick button in webpage 'which contains Validate function'

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2018
    Posts
    19

    VBA clicking Onclick button in webpage 'which contains Validate function'

    Hi Experts.

    Iam working on a project ''Automation IE'' need help on the same.

    I am trying to spool one excel report from website by giving From date and To Date are as inputs iam able to give enter dates with my code but iam unable click on generate button..

    Below is the HTML source code for from & To dates

    HTML Code:
    <input name="ctl00$ContentPlaceHolder1$txt_0" type="text" maxlength="10" id="txt_0" tabindex="1" class="watermarked" width="200px" selectionstart="txt_0" onchange="isDate2(this)" style="width: 200px;Height:20px;" autocomplete="off">
    
    <input name="ctl00$ContentPlaceHolder1$txt_1" type="text" maxlength="10" id="txt_1" tabindex="2" class="watermarked" width="200px" selectionstart="txt_1" onchange="isDate2(this)" style="width: 200px;Height:20px;" autocomplete="off">
    Below is the HTML source code for Export Report Button
    HTML Code:
    <input type="submit" name="ctl00$ContentPlaceHolder1$btnExportXLS" value="Export Report" onclick="if(!Validate()) return false;" id="btnExportXLS" tabindex="3" class="button blue" onmousedown="return isTxtwithfocus(event, this)" style="width:101px;float: none; margin-top: 2px;">
    And this is Function code
    HTML Code:
    function ValidateForm(src) { 
    assignvalue() 
    var src1 = document.getElementById("txt" + src); 
    
    if (src1.value != '') { 
    
    if (isDate2(src1.value, "txt_" + src) == false) { 
    return false 
    } 
    return true } 
    }
    This is my VBA code- Last two lines for click export button
    HTML Code:
    Sub User_Wise_Productivity()
    
    Dim From_Date As String
    Dim To_Date As String
    
    
    From_Date = InputBox("Enter report From date in (Ex: DD.MM.yyy)format")
    To_Date = InputBox("Enter report To date in (Ex: DD.MM.yyy)format")
    
    
    Set browser = CreateObject("internetexplorer.application")
    browser.Visible = True
    browser.navigate ("My URL")
    
    
    Do
    DoEvents
    Loop Until browser.readyState = 4
    
    
    browser.document.getElementById("txtUserName").Value = "Myid"
    browser.document.getElementById("txtPassword").Value = “Mypsw”
    
    browser.document.getElementById("selFund").selectedIndex = "21"
    browser.document.getElementById("btnSubmit").Click
    
    Do
    DoEvents
    Loop Until browser.readyState <> 4
    
    
    
    
    browser.navigate ("MY URL Page2")
    
    Do
    DoEvents
    Loop Until browser.readyState <> 4
    
    
    Dim reprt As String
    reprt = "11"
    
    
        With browser
            Set Post = .document.getElementById("ddlrptlist")
           For Each elem In Post.getElementsByTagName("option")
                If elem.Value = reprt Then elem.Selected = True: Exit For
            Next elem
    
      .document.getElementById("ddlrptlist").FireEvent ("onchange")
    
        End With
    
    Do
    DoEvents
    Loop Until browser.readyState <> 4
    
    browser.document.getElementById("txt_0").Value = From_Date
    browser.document.getElementById("txt_1").Value = To_Date
    
    Application.Wait (Now + TimeValue("0:00:02"))
    
    browser.document.getElementById("btnExportXLS").Focus
    browser.document.getElementById("btnExportXLS").Click
    End Sub

  2. #2
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    4,843

    Re: VBA clicking Onclick button in webpage 'which contains Validate function'

    Not only is this a "question" in the CodeBank area, it's a VBA question (not VB6), and it's also basically a duplicate of this post.
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  3. #3
    Hyperactive Member
    Join Date
    Aug 2016
    Posts
    293

    Re: VBA clicking Onclick button in webpage 'which contains Validate function'

    Quote Originally Posted by devendra.dvm View Post
    Hi Experts.

    Iam working on a project ''Automation IE'' need help on the same.

    I am trying to spool one excel report from website by giving From date and To Date are as inputs iam able to give enter dates with my code but iam unable click on generate button..

    Below is the HTML source code for from & To dates

    HTML Code:
    <input name="ctl00$ContentPlaceHolder1$txt_0" type="text" maxlength="10" id="txt_0" tabindex="1" class="watermarked" width="200px" selectionstart="txt_0" onchange="isDate2(this)" style="width: 200px;Height:20px;" autocomplete="off">
    
    <input name="ctl00$ContentPlaceHolder1$txt_1" type="text" maxlength="10" id="txt_1" tabindex="2" class="watermarked" width="200px" selectionstart="txt_1" onchange="isDate2(this)" style="width: 200px;Height:20px;" autocomplete="off">
    Below is the HTML source code for Export Report Button
    HTML Code:
    <input type="submit" name="ctl00$ContentPlaceHolder1$btnExportXLS" value="Export Report" onclick="if(!Validate()) return false;" id="btnExportXLS" tabindex="3" class="button blue" onmousedown="return isTxtwithfocus(event, this)" style="width:101px;float: none; margin-top: 2px;">
    And this is Function code
    HTML Code:
    function ValidateForm(src) { 
    assignvalue() 
    var src1 = document.getElementById("txt" + src); 
    
    if (src1.value != '') { 
    
    if (isDate2(src1.value, "txt_" + src) == false) { 
    return false 
    } 
    return true } 
    }
    This is my VBA code- Last two lines for click export button
    HTML Code:
    Sub User_Wise_Productivity()
    
    Dim From_Date As String
    Dim To_Date As String
    
    
    From_Date = InputBox("Enter report From date in (Ex: DD.MM.yyy)format")
    To_Date = InputBox("Enter report To date in (Ex: DD.MM.yyy)format")
    
    
    Set browser = CreateObject("internetexplorer.application")
    browser.Visible = True
    browser.navigate ("My URL")
    
    
    Do
    DoEvents
    Loop Until browser.readyState = 4
    
    
    browser.document.getElementById("txtUserName").Value = "Myid"
    browser.document.getElementById("txtPassword").Value = “Mypsw”
    
    browser.document.getElementById("selFund").selectedIndex = "21"
    browser.document.getElementById("btnSubmit").Click
    
    Do
    DoEvents
    Loop Until browser.readyState <> 4
    
    
    
    
    browser.navigate ("MY URL Page2")
    
    Do
    DoEvents
    Loop Until browser.readyState <> 4
    
    
    Dim reprt As String
    reprt = "11"
    
    
        With browser
            Set Post = .document.getElementById("ddlrptlist")
           For Each elem In Post.getElementsByTagName("option")
                If elem.Value = reprt Then elem.Selected = True: Exit For
            Next elem
    
      .document.getElementById("ddlrptlist").FireEvent ("onchange")
    
        End With
    
    Do
    DoEvents
    Loop Until browser.readyState <> 4
    
    browser.document.getElementById("txt_0").Value = From_Date
    browser.document.getElementById("txt_1").Value = To_Date
    
    Application.Wait (Now + TimeValue("0:00:02"))
    
    browser.document.getElementById("btnExportXLS").Focus
    browser.document.getElementById("btnExportXLS").Click
    End Sub
    i test you code in vb6, have no error

    Code:
    <input name="ctl00$ContentPlaceHolder1$txt_0" type="text" maxlength="10" id="txt_0" tabindex="1" class="watermarked" width="200px" selectionstart="txt_0" onchange="isDate2(this)" style="width: 200px;Height:20px;" autocomplete="off">
    
    <input name="ctl00$ContentPlaceHolder1$txt_1" type="text" maxlength="10" id="txt_1" tabindex="2" class="watermarked" width="200px" selectionstart="txt_1" onchange="isDate2(this)" style="width: 200px;Height:20px;" autocomplete="off">
    
    <input type="submit" name="ctl00$ContentPlaceHolder1$btnExportXLS" value="Export Report" onclick="alert('hollow!')" id="btnExportXLS" tabindex="3" class="button blue" onmousedown="alert('hollow!')" style="width:101px;float: none; margin-top: 2px;">
    click may msgbox hellow

  4. #4
    Hyperactive Member
    Join Date
    Aug 2016
    Posts
    293

    Re: VBA clicking Onclick button in webpage 'which contains Validate function'

    Quote Originally Posted by devendra.dvm View Post
    Hi Experts.

    Iam working on a project ''Automation IE'' need help on the same.

    I am trying to spool one excel report from website by giving From date and To Date are as inputs iam able to give enter dates with my code but iam unable click on generate button..

    Below is the HTML source code for from & To dates

    HTML Code:
    <input name="ctl00$ContentPlaceHolder1$txt_0" type="text" maxlength="10" id="txt_0" tabindex="1" class="watermarked" width="200px" selectionstart="txt_0" onchange="isDate2(this)" style="width: 200px;Height:20px;" autocomplete="off">
    
    <input name="ctl00$ContentPlaceHolder1$txt_1" type="text" maxlength="10" id="txt_1" tabindex="2" class="watermarked" width="200px" selectionstart="txt_1" onchange="isDate2(this)" style="width: 200px;Height:20px;" autocomplete="off">
    Below is the HTML source code for Export Report Button
    HTML Code:
    <input type="submit" name="ctl00$ContentPlaceHolder1$btnExportXLS" value="Export Report" onclick="if(!Validate()) return false;" id="btnExportXLS" tabindex="3" class="button blue" onmousedown="return isTxtwithfocus(event, this)" style="width:101px;float: none; margin-top: 2px;">
    And this is Function code
    HTML Code:
    function ValidateForm(src) { 
    assignvalue() 
    var src1 = document.getElementById("txt" + src); 
    
    if (src1.value != '') { 
    
    if (isDate2(src1.value, "txt_" + src) == false) { 
    return false 
    } 
    return true } 
    }
    This is my VBA code- Last two lines for click export button
    HTML Code:
    Sub User_Wise_Productivity()
    
    Dim From_Date As String
    Dim To_Date As String
    
    
    From_Date = InputBox("Enter report From date in (Ex: DD.MM.yyy)format")
    To_Date = InputBox("Enter report To date in (Ex: DD.MM.yyy)format")
    
    
    Set browser = CreateObject("internetexplorer.application")
    browser.Visible = True
    browser.navigate ("My URL")
    
    
    Do
    DoEvents
    Loop Until browser.readyState = 4
    
    
    browser.document.getElementById("txtUserName").Value = "Myid"
    browser.document.getElementById("txtPassword").Value = “Mypsw”
    
    browser.document.getElementById("selFund").selectedIndex = "21"
    browser.document.getElementById("btnSubmit").Click
    
    Do
    DoEvents
    Loop Until browser.readyState <> 4
    
    
    
    
    browser.navigate ("MY URL Page2")
    
    Do
    DoEvents
    Loop Until browser.readyState <> 4
    
    
    Dim reprt As String
    reprt = "11"
    
    
        With browser
            Set Post = .document.getElementById("ddlrptlist")
           For Each elem In Post.getElementsByTagName("option")
                If elem.Value = reprt Then elem.Selected = True: Exit For
            Next elem
    
      .document.getElementById("ddlrptlist").FireEvent ("onchange")
    
        End With
    
    Do
    DoEvents
    Loop Until browser.readyState <> 4
    
    browser.document.getElementById("txt_0").Value = From_Date
    browser.document.getElementById("txt_1").Value = To_Date
    
    Application.Wait (Now + TimeValue("0:00:02"))
    
    browser.document.getElementById("btnExportXLS").Focus
    browser.document.getElementById("btnExportXLS").Click
    End Sub
    i test you code in vb6, have no error

    Code:
    <input name="ctl00$ContentPlaceHolder1$txt_0" type="text" maxlength="10" id="txt_0" tabindex="1" class="watermarked" width="200px" selectionstart="txt_0" onchange="isDate2(this)" style="width: 200px;Height:20px;" autocomplete="off">
    
    <input name="ctl00$ContentPlaceHolder1$txt_1" type="text" maxlength="10" id="txt_1" tabindex="2" class="watermarked" width="200px" selectionstart="txt_1" onchange="isDate2(this)" style="width: 200px;Height:20px;" autocomplete="off">
    
    <input type="submit" name="ctl00$ContentPlaceHolder1$btnExportXLS" value="Export Report" onclick="alert('123hollow!')" id="btnExportXLS" tabindex="3" class="button blue" onmousedown="alert('hollow456!')" style="width:101px;float: none; margin-top: 2px;">
    click may msgbox hellow

    if button have focus,Mouse click pop up ""hollow456!"", Keyboard press enter pop up "123hollow!"
    Last edited by xxdoc123; Dec 4th, 2018 at 06:31 PM.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Dec 2018
    Posts
    19

    Re: VBA clicking Onclick button in webpage 'which contains Validate function'

    Hi xxdoc123,


    thanks for the reply.. this line of code is working fine.

    browser.document.getElementById("btnExportXLS").Click

    . not getting any error but excel report is not getting generate.. and there is no page load problem. if see at HTML code of button. there is onclick function**"Validate()"** in that. my guess iss after validating form with this function then only excel file will get spool

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Dec 2018
    Posts
    19

    Re: VBA clicking Onclick button in webpage 'which contains Validate function'

    Hi Elroy,

    yes im looking for VBA only.. if any help with is greatly appreciated.. the other post which you have mentioned.. that question not reflecting in the forum when i posted then i thot its not submitted properly.. that's why re-posted the same.

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Dec 2018
    Posts
    19

    Re: VBA clicking Onclick button in webpage 'which contains Validate function'

    please guide how to delete that post and same im not able to view in the forum.

  8. #8
    Hyperactive Member
    Join Date
    Aug 2016
    Posts
    293

    Re: VBA clicking Onclick button in webpage 'which contains Validate function'

    I doubt if you succeeded in IE, you may used ie to test.may be you can find why. I suggested you used ie documentcomplete event

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Dec 2018
    Posts
    19

    Re: VBA clicking Onclick button in webpage 'which contains Validate function'

    Hi xxdoc123,

    Could you please help me with the code for the same.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width