简体   繁体   English

在whatsapp网站(javascript)的联系人列表中单击联系人之一

[英]Click one of contact in contact list in whatsapp web (javascript)

I try to use JavaScript to perform a click action to click a contact form contact list in order to open a chat in Whatsapp Web. 我尝试使用JavaScript执行单击操作以单击联系人表单联系人列表,以便在Whatsapp Web中打开聊天。

I use normal click action to click but not working, like 我使用普通的点击操作来点击但无法正常工作,例如

var div = document.querySelector('.infinite-list-item')[0];
div.click();

And i know whatsapp web is made by react js, ant special to perform a click? 而且我知道whatsapp网站是由react js制作的,需要执行一个点击才能进行蚂蚁操作吗?

I even use jQuery click() function but still not working, what should I use? 我什至使用jQuery click()函数,但仍无法正常工作,该怎么用?


You're using document.querySelector() and then trying to access it as if it was a data structure. 您正在使用document.querySelector() ,然后尝试像访问数据结构一样对其进行访问。

document.querySelector() will return only one DOM element. document.querySelector()将仅返回一个DOM元素。 You should try using document.querySelectorAll()[0] if you want to put all the contacts in a structure. 如果要将所有联系人放入结构中,应尝试使用document.querySelectorAll()[0]

Solution: 解:

    var itemList = document.querySelectorAll('.infinite-list-item');
    itemList[0].click();

Also, this would work as an alternative solution ( though using querySelector instead of querySelectorAll to target a class name that is used more than once is not at all recommended ): 同样,这可以作为替代解决方案(尽管不建议使用querySelector而不是querySelectorAll来定位多次使用的类名):

    var div = document.querySelector('.infinite-list-item');
    div.click();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM