Jump to content

How do you view an "Attribute" in MsgBox [Solved]


Recommended Posts

I am having a hard time understanding why this is not working. I was hoping some one could help explain it to me. 

$tags = $oIE.document.GetElementsByTagName("input")
   For $tag in $tags
$class_value = $tag.GetAttribute("class")

If string($class_value) = "fTs-p3298-l0 wplEditControl" Then
   $target = $tag
      ExitLoop
   EndIF
Next

MsgBox(0,"",$target)

If $target = "fTs-p3298-l0 wplEditControl" THEN MsgBox(0,"","itworked")

I have tried 

 MsgBox(0,"",$target.Attribute)

 MsgBox(0,"",$target.Value)

 MsgBox(0,"",$target.InnerText)

I would expect to see this in the msgbox

fTs-p3298-l0 wplEditControl

 

Edited by SkysLastChance

You miss 100% of the shots you don't take. -Wayne Gretzky -Michael Scott

Link to comment
Share on other sites

Try this logic:

$bOk=False

;...  

$tags = $oIE.document.GetElementsByTagName("input")
   For $tag in $tags
$class_value = $tag.GetAttribute("class")

If string($class_value) = "fTs-p3298-l0 wplEditControl" Then
      MsgBox(0,$class_value,"itworked")
      $bOk=True
      ExitLoop
   EndIF
Next
   
if Not $bOk Then MsgBox(0,"","Error")

$tag isn't a string it's a element. The attribute is already saved in $class_value as string.

Link to comment
Share on other sites

Its strange that $Target.Value didn't work unless it was empty, but as AutoBert pointed out $Target variable is an Element Object so you would still need to treat it as an object see example below:
nb: For the example please open https://supsystic.com/example/contact-us-form/ in IE first, then run the code below

  1. It should find the "Last Name" field using the attribute "name"
  2. Add "Subz" value to the "Last name" field
  3. Assign $oInput to $oTag
  4. Exitloop
  5. Print the $oTag "data-name" attribute to the console
  6. Print the $oTag "Value" to the console (should say "Subz")

nb1: You normally can't use ".InnerText" with Inputs as these tags normally doesn't require closing aka </input>.
nb2: You would still require to use "GetAttribute" with the object not just "Attribute"

Hope that helps.

#include <IE.au3>

Global $oIE = _IECreate("https://supsystic.com/example/contact-us-form/", 1)
Global $oInputs = _IETagNameGetCollection($oIE, "Input")
If IsObj($oInputs) Then
    For $oInput in $oInputs
        If $oInput.GetAttribute("name") = "fields[last_name]" Then
            $oInput.Value = "Subz"
            $oTag = $oInput
            ExitLoop
        EndIf
    Next
EndIf
ConsoleWrite("$oTag Data-Name Attribute = " & $oTag.GetAttribute("data-name") & @CRLF)
ConsoleWrite(StringStripWS("$oTag Value = " & $oTag.Value, 7) & @CRLF)

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...