Can';t在“中使用javascript模拟点击事件”;web应用程序“;
我已经搜索了很多关于这方面的信息,但还没有找到解决方案 我的问题是,我正在创建一个扩展来加速几个网页的移动,我已经用很多网页来管理它,但是我遇到了一些我无法用Javascript模拟点击的情况,我不知道怎么做 其中一个页面是这样的:该页面位于西班牙语域,因此我不知道他们是否可以从另一个国家访问该页面(没有vpn),尽管我认为使用domain.com可以工作 代码如下,非常简单Can';t在“中使用javascript模拟点击事件”;web应用程序“;,javascript,html,web-applications,click,Javascript,Html,Web Applications,Click,我已经搜索了很多关于这方面的信息,但还没有找到解决方案 我的问题是,我正在创建一个扩展来加速几个网页的移动,我已经用很多网页来管理它,但是我遇到了一些我无法用Javascript模拟点击的情况,我不知道怎么做 其中一个页面是这样的:该页面位于西班牙语域,因此我不知道他们是否可以从另一个国家访问该页面(没有vpn),尽管我认为使用domain.com可以工作 代码如下,非常简单 var deportesActivos = document.getElementsByClassName("categ
var deportesActivos = document.getElementsByClassName("categoryListItemWrapper contentSelectorItemButton")
for(let i=0;i<deportesActivos.length;i++){
let nombre = deportesActivos[i].lastChild.firstChild.innerText
if(nombre == data.deporte){
deportesActivos[i].click()
}
}
匹配后,单击以输入链接
问题是,单击并不能模拟我。
我买了你点击的元素,我手动点击,它可以工作,我试着点击网页的其他元素,但它不工作,我试着给元素一个“点击侦听器”,它也不工作。
该页面的HTML如下所示:
我不知道这是否有帮助,但在使用Ionic应用程序构建网站时,两者都不起作用
点击事件不能完全模拟用户点击。它只会对目标元素(以及任何父元素)触发
onClick
处理程序
如果单击按钮时您只是重定向到一个新的URL,那么您可以在循环中执行此操作
// get the links, not the buttons
var deportesActivos = document.getElementsByClassName("categoryListItemWrapper contentSelector");
for (let i=0; i < deportesActivos.length; i++) {
// Drill down one extralevel to get the button text
let nombre = deportesActivos[i].firstChild.lastChild.firstChild.innerText;
if (nombre === data.deporte) {
// Redirect to the href in the link
window.location.href = deportesActivos[i].href;
}
}
//获取链接,而不是按钮
var-lakesActivos=document.getElementsByClassName(“categoryListItemWrapper contentSelector”);
for(设i=0;i
window.open(lakesActivos[i].parentElement.href),当您单击这些div时,您将转到该网站中其家长的href链接,特别是您的解决方案将起作用,但如果我无法捕获url怎么办?谢谢你的回答!不确定这个用例。你必须有一个URL重定向到某个地方,它可以是
标签的href
,按钮上的数据属性(例如数据href=”http://...“
),或以某种方式存储在JavaScript中的URL(以及其他可能性)。如果此答案解决了您的问题,请接受并投票表决。谢谢当我尝试重定向时,这应该可以工作,但当我尝试显示一些隐藏的内容时,它不能工作,例如:,code->因为您的手风琴可能是由JavaScript驱动的,所以触发onClick似乎可以工作。如果不是,您可以直接将“collapsed”的值更改为false。
// get the links, not the buttons
var deportesActivos = document.getElementsByClassName("categoryListItemWrapper contentSelector");
for (let i=0; i < deportesActivos.length; i++) {
// Drill down one extralevel to get the button text
let nombre = deportesActivos[i].firstChild.lastChild.firstChild.innerText;
if (nombre === data.deporte) {
// Redirect to the href in the link
window.location.href = deportesActivos[i].href;
}
}