Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88854

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

$
0
0

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

<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

<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

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

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

Any help greatly appreciated. thanks in advance.


Viewing all articles
Browse latest Browse all 88854

Trending Articles