I'm coding a script using AutoIt V3 and I'm having trouble finding the "object name" when I inspect an element

907 views Asked by At

I'm new to scripts and I'm coding something that will log me in to my facebook and go to a friends wall and post something for them. I'm stuck in the last part. I can't get the object name of the button "post".

Can someone help me finalize my code?

#include <IE.au3>

Call("fcb")

Func fcb()
Global $oIE = _IECreate("https://www.facebook.com/")

local $userName = _IEGetObjByName($oIE, "email")
local $passWord = _IEGetObjByName($oIE, "pass")
local $log = _IEGetObjById($oIE, "loginbutton")

_IEFormElementSetValue($userName,"myemail")
_IEFormElementSetValue($passWord,"mypasscode")

_IEAction($log,"click")

EndFunc

Call("fcb2")

Func fcb2()
Global $oIE = _IECreate(https://www.facebook.com/myfriednspage)
local $box = _IEGetObjById($oIE, "u_0_1a")
_IEAction($box,"click")
local $typeInWall = _IEGetObjById($oIE, "u_0_1a")
_IEFormElementSetValue($typeInWall,"hi ugly")
local $toSubmit = _IEGetObjectType($oIE, "submit")
_IEAction($toSubmit,"click")

EndFunc

This is the code I get when I click inspect element on the "post" button:

<button class="_42ft _4jy0 _11b _4jy1 selected _51sy"
type="submit" value="1" data-ft="{"tn":"+{"}">Post</button>

I think this is the line I'm having trouble with:

"local $toSubmit = _IEGetObjectType($oIE, "submit")"
1

There are 1 answers

0
Milos On

For this you would need to make your own function.

You need to list all buttons and then search for one with "Post" as innertext.

Something like this:

$oPostBtn = _IEGetObjByText($oIE, "button", "Post")

$oPostBtn.click

Func _IEGetObjByText($oObj, $tag, $text)

    Local $oButtons = _IETagNameGetCollection($oObj, $tag)

    For $oButton In $oButtons
        if $oButton.innertext == $text Then Return SetError(0, 0, $oButton)
    Next

    Return SetError(1, 0, False)

EndFunc

Note that there may be more then one "Post" button on a page. The safest way is to narrow the search down to a form object. You find a desired form and the use that object as first parameter in IEGetObjByText.