javascript - 我正在使用 AutoIt V3 编写脚本,但在检查元素时找不到 "object name"

标签 javascript php jquery autoit scite

我是脚本的新手,我正在编写一些代码,让我登录到我的 facebook 并转到 friend 墙并为他们张贴一些东西。我被困在最后一部分。我无法获取“发布”按钮的对象名称。

有人可以帮我完成我的代码吗?

#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

这是我在“发布”按钮上单击检查元素时得到的代码:

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

我认为这是我遇到问题的行:

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

最佳答案

为此,您需要创建自己的函数。

您需要列出所有按钮,然后搜索一个以“发布”作为内文的按钮。

像这样:

$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

请注意,一个页面上可能有多个“发布”按钮。最安全的方法是将搜索范围缩小到表单对象。您找到所需的表单并将该对象用作 IEGetObjByText 中的第一个参数。

关于javascript - 我正在使用 AutoIt V3 编写脚本,但在检查元素时找不到 "object name",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30747047/

相关文章:

javascript - 从 Javascript 调用组件中的方法 - Angular2

php - 刷新内容,不加载

jquery - 导航栏不会中心 Bootstrap

javascript - 可以在 Typescript 中扩展类型吗?

javascript - 在 Zend Framework 1.12 中保存之前确认验证

php - 使用Jquery发布单个变量

php - 如何在下拉列表中显示选中的项目名称?

javascript - jQuery Tablesorter 不排序列

javascript - 很好地在 gulp 任务中抛出错误

php - 如何散列和加盐密码