自动点击 JavaScript 按钮

发布于 2024-10-31 15:13:56 字数 1118 浏览 0 评论 0原文

所以我有一个带有如下代码的按钮:

<div style="text-indent: 0pt; visibility: inherit;" id="button5061">
    <a title="Continue" href="javascript:if(%20button5061.hasOnUp%20)%20button5061.onUp()" name="button5061anc">
        <img width="82" height="25" border="0" style="cursor: pointer;" alt="Continue" src="images/continueoff.gif" name="button5061Img">
    </a>
</div>

我需要用 javascript 单击它。现在我正在使用 firefox 扩展 Chickenfoot,它允许我使用 javascript 解释器和一些自定义命令来编写网站脚本。

http://groups.csail.mit.edu/uid/chickenfoot/api.html

我尝试使用 xPath (//div/a[@title='Continue']/..) 选择它,它找到了它,但是当我单击() 时,什么也没有发生。 以下是我尝试过的一些事情:

click(find(new XPath("//img[@alt='Continue']/..")))
click(find(new XPath("//img[@alt='Continue']/../..")))
click("continue")
click("Continue")
click("images/continueoff.gif")
click("continueoff.gif")
click(find("Continue"))
click(find("Continue").element)
click(find("images/continueoff.gif"))

我知道这是一个相当具体的问题,但任何关于尝试什么的想法将不胜感激。

So I have a button with code like this:

<div style="text-indent: 0pt; visibility: inherit;" id="button5061">
    <a title="Continue" href="javascript:if(%20button5061.hasOnUp%20)%20button5061.onUp()" name="button5061anc">
        <img width="82" height="25" border="0" style="cursor: pointer;" alt="Continue" src="images/continueoff.gif" name="button5061Img">
    </a>
</div>

And I need to click it with javascript. Right now I am using the firefox extension Chickenfoot which allows me to script the site with a javascript interpreter with some custom commands.

http://groups.csail.mit.edu/uid/chickenfoot/api.html

I have tried selecting it with xPath (//div/a[@title='Continue']/..) which finds it, but when I click() it nothing happens.
Here are some of the things I have tried:

click(find(new XPath("//img[@alt='Continue']/..")))
click(find(new XPath("//img[@alt='Continue']/../..")))
click("continue")
click("Continue")
click("images/continueoff.gif")
click("continueoff.gif")
click(find("Continue"))
click(find("Continue").element)
click(find("images/continueoff.gif"))

I know this is a rather specific quesiton but any ideas on what to try would be much appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

绅士风度i 2024-11-07 15:13:56

html:

<div>
    <a href="#" onclick="alert('ok')">
        <img src="">
    </a>
</div>

javascript:

var xPathRes = document.evaluate ('//div[1]/a[1]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
xPathRes.singleNodeValue.click();

jsfiddle:

https://jsfiddle.net/7fm89aqd/

html:

<div>
    <a href="#" onclick="alert('ok')">
        <img src="">
    </a>
</div>

javascript:

var xPathRes = document.evaluate ('//div[1]/a[1]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
xPathRes.singleNodeValue.click();

jsfiddle:

https://jsfiddle.net/7fm89aqd/

路弥 2024-11-07 15:13:56

如果您尝试模拟用户点击它:

您可以像这样模拟点击:document.getElementById('theSubmitButton').click();

这是给您的一个示例:http://jsfiddle.net/gasWZ/1/

如果这不是您想要做的,您可以吗多解释一下吗?

If you're trying to simulate a user clicking on it:

You can simulate a click like this: document.getElementById('theSubmitButton').click();

Here's an example for ya: http://jsfiddle.net/gasWZ/1/

If that's not what you're trying to do, could you explain a bit more?

苄①跕圉湢 2024-11-07 15:13:56

将锚对象传递给函数并评估 name 属性不是很有效吗?

  1. 将 href 属性设置为 #
  2. 调用函数并传递 obj

<div style="text-indent: 0pt; visibility: inherit;" id="button____"> <a title="Continue" href="#" name="button____anc"> <img width="82" height="25" border="0" style="cursor: pointer;" alt="Continue" src="images/continueoff.gif" name="button____Img"> </a> </div>

Wouldn't it be effective to pass the anchor object to your function and evaluate the name attribute?

  1. set the href attribute to #
  2. call the function and pass the obj

<div style="text-indent: 0pt; visibility: inherit;" id="button____"> <a title="Continue" href="#" name="button____anc"> <img width="82" height="25" border="0" style="cursor: pointer;" alt="Continue" src="images/continueoff.gif" name="button____Img"> </a> </div>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文