-
Dec 3rd, 2018, 11:25 PM
#1
Thread Starter
Junior Member
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
-
Dec 4th, 2018, 03:20 PM
#2
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. To all, peace and happiness.
-
Dec 4th, 2018, 06:14 PM
#3
Fanatic Member
Re: VBA clicking Onclick button in webpage 'which contains Validate function'
Originally Posted by devendra.dvm
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
-
Dec 4th, 2018, 06:24 PM
#4
Fanatic Member
Re: VBA clicking Onclick button in webpage 'which contains Validate function'
Originally Posted by devendra.dvm
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.
-
Dec 7th, 2018, 03:47 AM
#5
Thread Starter
Junior Member
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
-
Dec 7th, 2018, 06:21 AM
#6
Thread Starter
Junior Member
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.
-
Dec 7th, 2018, 06:23 AM
#7
Thread Starter
Junior Member
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.
-
Dec 7th, 2018, 09:17 PM
#8
Fanatic Member
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
-
Dec 7th, 2018, 11:30 PM
#9
Thread Starter
Junior Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|