自动点击 JavaScript 按钮
所以我有一个带有如下代码的按钮:
<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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
html:
javascript:
jsfiddle:
https://jsfiddle.net/7fm89aqd/
html:
javascript:
jsfiddle:
https://jsfiddle.net/7fm89aqd/
如果您尝试模拟用户点击它:
您可以像这样模拟点击:
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?
将锚对象传递给函数并评估 name 属性不是很有效吗?
Wouldn't it be effective to pass the anchor object to your function and evaluate the name attribute?