在 VBScript 中,如何检查 IE 中 div 中的单个单词是否存在?
In VBScript how do you check if a single word in a div in IE exists?
我需要创建一个 If 语句来标识 IE div 中的特定词是否存在。
这是因为默认情况下,div 是空的。当用户单击创建帐户的按钮时,div 中会出现一个警告,表明用户已经拥有一个活动帐户。
“您已经有一个活动帐户,请登录”
但如果用户还没有帐户,div 将保持为空。
这是我正在创建的 ie 自动化工具的一部分。我只能使用 VBScript,不能使用 VBA 或其他任何东西。
我在 div 中查找的特定词是“active”。 Div 的 ID 是“activeAlert”
我已经尝试过 isObject、isEmpty、isNull、InStr 等,但似乎没有任何效果。下面是我需要做的用英文写出来的:
If doc.getElementByID("activeAlert") contains the word "active" then
msgbox("You already have an active account")
Exit Sub
Else
Do something
End If
请记住,我对使用 VBScript 还是很陌生,所以请详细解释您的答案,我们将不胜感激。
找到元素后,您可以检查其 InnerHTML
或 InnerText
:
Dim objElement
Set objElement = doc.getElementByID("activeAlert")
If Not objElement Is Nothing Then
Dim sText
sText = objElement.InnerText
If InStr(sText, "active") > 0 Then
MsgBox ("You already have an active account")
Exit Sub
Else
' Not found
End If
Else
' Not found
End If
我需要创建一个 If 语句来标识 IE div 中的特定词是否存在。
这是因为默认情况下,div 是空的。当用户单击创建帐户的按钮时,div 中会出现一个警告,表明用户已经拥有一个活动帐户。
“您已经有一个活动帐户,请登录”
但如果用户还没有帐户,div 将保持为空。
这是我正在创建的 ie 自动化工具的一部分。我只能使用 VBScript,不能使用 VBA 或其他任何东西。
我在 div 中查找的特定词是“active”。 Div 的 ID 是“activeAlert”
我已经尝试过 isObject、isEmpty、isNull、InStr 等,但似乎没有任何效果。下面是我需要做的用英文写出来的:
If doc.getElementByID("activeAlert") contains the word "active" then
msgbox("You already have an active account")
Exit Sub
Else
Do something
End If
请记住,我对使用 VBScript 还是很陌生,所以请详细解释您的答案,我们将不胜感激。
找到元素后,您可以检查其 InnerHTML
或 InnerText
:
Dim objElement
Set objElement = doc.getElementByID("activeAlert")
If Not objElement Is Nothing Then
Dim sText
sText = objElement.InnerText
If InStr(sText, "active") > 0 Then
MsgBox ("You already have an active account")
Exit Sub
Else
' Not found
End If
Else
' Not found
End If