如何在Excel中运行网站表单,而无需使用Sendkeys? [英] How to run website forms in Excel without having to use Sendkeys?

查看:138
本文介绍了如何在Excel中运行网站表单,而无需使用Sendkeys?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Excel VBA在网站上填写表单。我创建了一个InternetExplorer.Application,导航到页面并查找一堆数据,使用如果UserForm1.TC2.Value = True Then 或类似 PostCode = objIE.document.getElementsByName(ProjectFile-ProposalAddress-PostCode)(0).Value 等。

I am trying fill out a form on a website using Excel VBA. I have created an InternetExplorer.Application, navigated to the page and looked up a bunch of data, using If UserForm1.TC2.Value = True Then or something like PostCode = objIE.document.getElementsByName("ProjectFile-ProposalAddress-PostCode")(0).Value and the like.

之后,我导航到一个新页面,并使用我以前的数据来填写它。

Afterwards, I navigate to a new page, and look to fill it out using my previous data.

这是我遇到麻烦的地方。我想勾选一个复选框'新许可',其代码是;

And this is where I run into trouble. I want to tick a check box 'New Permit', and its code is;

<form id="document-form">
<div class="generate-form form-horizontal">
<div class="form-group"><label class="col-sm-3 control-label"><span>New Permit</span></label><div class="input col-sm-7">
<div class="checkbox">
<input type="checkbox" data-bind="checked: NewPermit" />
</div></div></div><div class="form-group"><label class="col-sm-3 control-label"><span>Staged Permit</span></label><div class="input col-sm-7">
<div class="checkbox">
    <input type="checkbox" data-bind="checked: StagedPermit" />
</div>

哪个没有名称锁定成。我不是一个HTML专家,但还有一些更多的代码引用了这个tickbox(我认为)

Which has no name to lock into. I'm not a HTML expert, but there is some more code that refers to this tickbox (I think)

 var model = {  "NewPermit": null,   "StagedPermit": null,  "AmendedPermit": null,

等。

我已经使用 .getElementsByTagName(Span)与各种 .tagName 等。以下结果适用于新的许可证框:

I have run a loop through the code using .getElementsByTagName("Span") with various .tagName etc. The following results is for the New Permit box:

.tagName = Span

.outerHTML =新许可

.outerText = .innerHTML = .innertext =新许可

.outerText = .innerHTML = .innertext = New Permit

.isContentEditable = False

.tostring = [object HTMLSpanElement]

.tostring = [object HTMLSpanElement]

.ID =

这是密码登录的背后,我无法公开发布链接。

This is behind a password log in, and I cannot post the link publicly. But can work through PM etc to get to the answer.

推荐答案

使用 getElementsByTagName('input') 然后使用 Checked = True

Dim element as Object
element = getElementsByTagName('input')
element.Checked = True

假设复选框是页面上唯一的输入元素。如果没有,请循环并确定所需的复选框

这篇关于如何在Excel中运行网站表单,而无需使用Sendkeys?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆