Jump to content
SkysLastChance

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

Life's simple. You make choices and you don't look back.

Share this post


Link to post
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.

Share this post


Link to post
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)

 

Share this post


Link to post
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

  • Similar Content

    • By moimon
      Hi all. 
      Sorry if my words are confusing because I am not good at English.
      I am writing code to embed website with Recaptcha in GUI. And then, the code will automatically press the "I'm not a robot" button. The problem here is:
         - The code still works fine when entering iFrame to interact with Recaptcha with the URL is "https://www.google.com/recaptcha/api2/demo"
      <snip>
       
         - But for other URLs (such as "https://recaptcha-demo.appspot.com/recaptcha-v2-checkbox.php"), the code cannot be entered into the iframe.
       
      Code:
      <snip>  
      I did a lot of research but didn't know why.
       I sincerely thanks for the help. 
    • By SkysLastChance
      I am pretty sure the site that I am using was updated and now I am not seeing the same tags/elements that I used to. I tried using a UIAspy to see if I could grab them that way with no luck. 
      What do I need to do to be able to automate this again. Are the elements hidden somewhere?
      Instead of highlighting established account is highlights all of the web page almost. How can I get to the detail again? 
      I used to grab establish account by the name. Now I have nothing to even try to grab. 
      There are not elements in the event viewer either. 
       


       
      This is what happens when I try to inspect the element and click established account. 
      I get the same type of results in chrome
    • By yffulf
      Is there probably a way to click ie popup button and hide or invisible popup button in the same time?
      I try to use WinSetState @SW_hide ,
      the result is ie crashing or no response because button hide and the next click command won't work...
      $oForm=_IEFormGetObjByName($oIE,"form1") $obutton=_IEFormElementGetObjByName($oForm,"btn_OK") $hWnd = _IEPropertyGet($oIE, "hwnd") _IEAction($obutton,"focus") ControlSend($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{Enter}") WinWait("", "確定存檔嗎?") WinSetState("","確定存檔嗎?",@SW_Hide) ControlClick("", "確定存檔嗎?", "[CLASS:Button; TEXT:確定; Instance:1;]")  
    • By _leo_
      Hey there!
      I am having a problem with clicking a button in IE. As you can see in the code, there would be a class name to click it, but since this button exists several times with exactly the same code, I can only use the "Noch nicht veröffentlicht" to separate it from the others. But this part is just pure text without any classification. 
      "<div class="checkmark" data-v-1e5b1f70=""><svg xmlns="http://www.w3.org/2000/svg" class="icon" viewBox="0 0 16 16" data-v-1e5b1f70=""><circle cx="8" cy="8" r="8" data-v-1e5b1f70="" /></svg></div>Noch nicht veröffentlicht"
      I was trying to click it with:
      #include <IE.au3> local $oNNVs = _IEFormGetCollection($oIE2) For $oNNV in $oNNVs If String($oNNV.innertext) = "Noch nicht veröffentlicht" Then _IEAction($oNNV, "click") EndIf Next and:
      $inputs = $oIE2.document.getElementsByTagName("div") For $input In $inputs If $input.innertext == "Noch nicht veröffentlicht" then $input.click() EndIf Next But nothing seems to work. Thanks for the help!
    • By TXTechie
      Hello Everyone,
      I'm looking for a way to use an already open Internet Explorer (IE) window (if one is up and running) and then navigate to a new URL in a new IE tab.
      I thought that _IECreate would easily meet my needs. However, when I use the following script:
      #include <IE.au3> Local $oIE = _IECreate("https://" & $Server & ":8444/", 1, 1, 0, 1) ...with one or more open IE windows, it still opens yet a new IE window.
      Are there any other ideas for how to reliably use an already open IE windows and then how to open a new tab in IE to navigate to a new URL?
      Regards,
      TX Techie
×
×
  • Create New...