使用VBA操纵IE提交表单(textarea字段出现问题) [英] Using VBA to manipulate IE with submitting form (trouble with textarea field)

查看:160
本文介绍了使用VBA操纵IE提交表单(textarea字段出现问题)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello StackOverflow社区,

Hello StackOverflow community,

我有一个有关使用VBA操纵IE的问题.

I have a question about using VBA to manipulate IE.

该代码是关于以网站形式插入数据.到目前为止,除以下"textarea"字段外,一切工作正常:

The code is about inserting data in a form of a website. Everything worked out well so far, except for the following "textarea" field:

<textarea cols="1" rows="1" id="id_content" name="name_content" class="htmleditor">Content of the textarea is displayed here</textarea>

除了实际字段(如上所述,它来自textarea类型)之外,还有htmleditor中包含的来自type button的另外两个元素.

Apart from the actual field (which is from the type textarea as mentioned above) there are also a couple more elements from type button which are included in the htmleditor.

我要确切地做的是更改文本字段中的文本.因此,我希望能够编写一些不同的内容,而不是此处显示文本区域的内容".如果可能的话,还可以更改格式,例如某些部分以粗体显示,等等.然后提交表格.

What I want to do precisely is to change the text in the text field. So instead of "Content of the textarea is displayed here" I want to be able to write something different. If possible also change the format as well, e.g. some parts bold etc. And afterwards submit the form.

我到目前为止使用的代码:

The code I use so far:

Dim IEApp As SHDocVw.InternetExplorer
Set IEApp = New SHDocVw.InternetExplorer

Dim htmlDocument As htmlDocument
Dim objNotes As Object
Dim strNotes As String

With IEApp
    IEApp.Visible = True
    IEApp.Navigate "..."
    Do: Loop Until IEApp.Busy = False
    Do: Loop Until IEApp.document.ReadyState = "complete"
End With

Set objNotes = IEApp.document.getElementsByName("name_content")(0)

MsgBox objNotes.innerText ' 1)
MsgBox objNotes.innerHTML ' 2)
MsgBox objNotes.outerHTML ' 3)
MsgBox objNotes.Value ' 4)

objNotes.Value = "Hello World" 'Here I want to change the text in the textfield

MsgBox objNotes.innerText ' 5)
MsgBox objNotes.innerHTML ' 6)
MsgBox objNotes.outerHTML ' 7)
MsgBox objNotes.Value ' 8)

IEApp.document.forms(0).submit

MsgBox命令提供以下内容

The MsgBox commands give the following

1) <p>Content of the textarea is displayed here</p>
2) &lt;p&gt;Content of the textarea is displayed here&lt;/p&gt;
3) <textarea name="name_content" class="htmleditor" id="id_content" aria-hidden="true" style="display: none;" rows="1" cols="1">&lt;p&gt;Content of the textarea is displayed here&lt;/p&gt;</textarea>
4) <p>Content of the textarea is displayed here</p>

5) <p>Hello World</p>
6) &lt;p&gt;Hello World&lt;/p&gt;
7) <textarea name="name_content" class="htmleditor" id="id_content" aria-hidden="true" style="display: none;" rows="1" cols="1">&lt;p&gt;Hello World&lt;/p&gt;</textarea>
8) <p>Hello World</p>

但是成功提交表单后,页面不会更改.

But after successfully submitting the form the page isn't changed.

到目前为止我尝试过的事情:

What I tried so far:

  • getElementByID代替getElementsbyName
  • 通过浏览网站的所有元素并直接引用来搜索该元素
  • 更改innerText,innerHTML,outerHTML,值的值
  • 因为aria-Hidden = True试图通过VBA进行更改,但我找不到合适的方法
  • 将新的textArea变量定义为Object/HTMLTextAreaElement/HTMLRichtextElement/HTMLInputTextElement/HTMLAreaElement并通过此值更改值,但没有任何数据类型会影响它
  • 将公式设置为活动状态,使其集中显示,但无法使用SendKeys函数以这种方式编写文本

您知道还有什么可以做的吗?

Any idea what else could be done?

推荐答案

对于TextArea,不要使用byid或byname,而应使用byTagName 我相信您必须使用功能 getElementsbyTagName

For TextArea not use byid or byname, but byTagName I Believe you have to use function getElementsbyTagName

这篇关于使用VBA操纵IE提交表单(textarea字段出现问题)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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