gpt4 book ai didi

html - 使用 Excel VBA 单击网站中的复选框

转载 作者:行者123 更新时间:2023-12-04 20:52:25 24 4
gpt4 key购买 nike

有一个网站有一些我想要用于我的工作的数据。我登录检查一些复选框并提交,然后网站将向我发送一封包含我的数据的电子邮件。但是接收我的信息需要很长时间,所以我想自动化它,所以每天早上的第一个小时都需要信息,就像我需要它时已经在我的电子邮件中一样。

我修改了一些代码,我已经成功登录并转到需要单击复选框的页面(其中有三个),然后单击提交按钮。

Sub GetTable()

Dim ieApp As InternetExplorer
Dim ieDoc As Object
Dim ieTable As Object
Dim chkBox As Object

'create a new instance of ie
Set ieApp = New InternetExplorer

'you don’t need this, but it’s good for debugging
ieApp.Visible = True

'assume we’re not logged in and just go directly to the login page
ieApp.Navigate "http://mydata/aspx/mydataLogon.aspx?Language=2"
Do While ieApp.Busy: DoEvents: Loop
Do Until ieApp.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop

Set ieDoc = ieApp.Document

'fill in the login form – View Source from your browser to get the control names
With ieDoc.forms(0)
.txtUsername.Value = "usertest"
.txtPassword.Value = "test123"
.Submit
End With
Do While ieApp.Busy: DoEvents: Loop
Do Until ieApp.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop

'now that we’re in, go to the page we want
ieApp.Navigate "http://mydata/InventoryTracking/aspx/rptDefault.aspx?rpt=../aspx/invRptDetailReport.aspx"

Set ieDoc = ieApp.Document

With ieDoc

'I tried with getElementbyId, I dont get any error but the chkbox still comes as with a nothing value
Set chkBox = ieDoc.getElementByid("cblPlants_0")

'therefore these give error too, I dont know why. A an object variable or with block variable not set error
chkBox.Click
chkBox.Checked = True

'here I get an object variable or with block variable not set error
ieDoc.getElementByid("cblPlants_0").Click

.Submit
End With

End sub

我想要的复选框控件在其中:
'first there is a form and this is how the iframe is first called I think
<form name="_ctl1" method="post" action="rptDefault.aspx" id="_ctl1">
<table width="100%" HEIGHT="100%" cellpadding="0" cellspacing="0" border="0">
<TR>
<TD CLASS="Normal" COLSPAN="4"><IFRAME ID="IFRAME1" NAME="IFRAME1" SRC="../aspx/invRptDetailReport.aspx" frameborder="0" width="100%" height="100%"></IFRAME></TD>
</TR>

'Now the iframe1 goes like this

<form name="frmRptDetailReport" method="POST" action="invRptDetailReport.aspx" id="frmRptDetailReport">
<table id="htblMainBody" width="100%" cellpadding="0" cellspacing="0" border="0" bgcolor="#E5DBE2">

<tr><td <a id="lbtnSelect" href="javascript:__doPostBack(&#39;lbtnSelect&#39;,&#39;&#39;)"</a>
<div id="divChkboxlist" class="scrollingControlContainer scrollingCheckBoxList" onscroll="saveScrollPos();">
<table id="cblPlants" border="0" style="font-family:Arial;font-size:11px;width:275px;overflow: scroll"><tr>
<tr><td><input id="cblPlants_0" type="checkbox" name="cblPlants:0" onclick="javascript:setTimeout(&#39;__doPostBack(\&#39;cblPlants$0\&#39;,\&#39;\&#39;)&#39;, 0)" language="javascript" /><label for="cblPlants_0">1X1 -Confecciones</label></td>
</tr>

如何在此页面上选中此复选框?选中复选框后,我将收到我想要的电子邮件。

如果您需要更多信息,请告诉我

最佳答案

尝试

ieDoc.querySelector("#cblPlants_0").click

相当于:
ieDoc.getElementById("cblPlants_0").click

请记住在 .Navigate 步骤之后等待适当的页面加载,然后再尝试单击
While ieApp.Busy Or ieApp.readyState < 4: DoEvents: Wend

Set ieDoc = ieApp.Document

ieDoc.getElementById("cblPlants_0").click

在单击之前,您可能需要额外等待。使用 F8 进行单步测试。

您也可以尝试执行 javascript
ieDoc.parentWindow.execScript "javascript:setTimeout('__doPostBack(\'cblPlants$0\',\'\')', 0)"

关于html - 使用 Excel VBA 单击网站中的复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55404789/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com