admin 管理员组文章数量: 1086019
I'm trying to click all the links on a page, where the identifiers for the link I want to click are only a unique href, a generic title, and the text of the link.
I want to click all the links whose title text (or even the text of the link) are the same.
I've tried adapting other scripts for the purpose, but have had no luck. My current iteration is this:
var links = document.getElementByTitle("Download");
for (var i = 0; i < links.length; ++i) {
links[i].click();
}
which doesn't work because there is no method getElementByTitle. I feel like this is the best way to convey what I'm trying to do, though.
I'm trying to click all the links on a page, where the identifiers for the link I want to click are only a unique href, a generic title, and the text of the link.
I want to click all the links whose title text (or even the text of the link) are the same.
I've tried adapting other scripts for the purpose, but have had no luck. My current iteration is this:
var links = document.getElementByTitle("Download");
for (var i = 0; i < links.length; ++i) {
links[i].click();
}
which doesn't work because there is no method getElementByTitle. I feel like this is the best way to convey what I'm trying to do, though.
Share Improve this question asked Mar 7, 2014 at 23:14 AndrewAndrew 992 silver badges12 bronze badges 1- 1 "I want to click all the links whose title text (or even the text of the link) are the same." - The same as what? Are you saying you want to find any links that have the same title as other links and click all of those? Or where the title is the same as some predefined string? – nnnnnn Commented Mar 7, 2014 at 23:20
1 Answer
Reset to default 7"there is no method getElementByTitle."
No, but you can use the querySelectorAll()
method:
var links = document.querySelectorAll('a[title="Download"]');
for (var i = 0; i < links.length; i++) {
links[i].click();
}
That is supported in all modern browsers, including IE >= 9, or even IE8 with CSS2 selectors. Otherwise you can do this:
var links = document.getElementsByTagName("a");
for (var i = 0; i < links.length; i++) {
if (links[i].title === "Download")
links[i].click();
}
本文标签: google chromeJavascript console click links with certain titletextStack Overflow
版权声明:本文标题:google chrome - Javascript console: click links with certain titletext - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1743996644a2515696.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论