Javascript 在whatsapp web界面上触发向下键/向上键/按
我公司的ERP直到今天还运行得很好,但whatsapp在他们的web界面上做了一些改变,破坏了我的JS代码。如果你打开web.whatsapp.com,你会看到你可以在那里发送消息 我有一个自动脚本,可以搜索特定用户(他们欠我公司的债),并用whatsapp向他们发送消息。我通常这样做:Javascript 在whatsapp web界面上触发向下键/向上键/按,javascript,jquery,Javascript,Jquery,我公司的ERP直到今天还运行得很好,但whatsapp在他们的web界面上做了一些改变,破坏了我的JS代码。如果你打开web.whatsapp.com,你会看到你可以在那里发送消息 我有一个自动脚本,可以搜索特定用户(他们欠我公司的债),并用whatsapp向他们发送消息。我通常这样做: janela = window.open("https://web.whatsapp.com"); 页面加载后,我的系统使用以下非常简单的代码模拟单击搜索图标: evt_temp = document.cre
janela = window.open("https://web.whatsapp.com");
页面加载后,我的系统使用以下非常简单的代码模拟单击搜索图标:
evt_temp = document.createEvent("MouseEvents");
evt_temp.initEvent("mousedown",true,false);
$(janela.window.document).find("[data-icon=\"search\"]").get(0).dispatchEvent(evt_temp);
之后,我使用以下代码设置显示的输入元素的值:
$(janela.window.document).find("#input-chatlist-search").val("Contact Name");
在今天之前,当我执行上面的代码时,一切都运行得很好。现在,当我执行上面的代码时,一切看起来都很好(见下面的打印屏幕),但由于某种原因whatsapp没有触发搜索(我已经尝试在输入上触发keydown/up/press事件,但没有成功)。请参阅所附图片。这里也有同样的问题
我使用NWJS和VBScript解决了这个问题
我是如何做到的:
1) 我为NWJS编写了一个小应用程序(html),其中包含一个iframe
2) 关注使用javascript的wsp搜索文本输入
3) 使用NWJS api,运行VBScript以粘贴联系人的姓名
有关VBScript的详细信息
如果您需要更多帮助或代码,请询问
最好的问候基本上,NW JS是Chrome,但具有NODE-JS功能。这意味着它可以让你在系统上执行命令,或者在硬盘上读/写文件 1) 您必须下载NWJS() 2) 解压缩zip文件 3) 在nw.exe文件夹中创建一个名为“package.json”的文件 4) 将此添加到该文件:(应用程序的名称、版本和条目文件) 5) 现在您必须编写“index.html”,并且该html将显示在您的应用程序中 6) 在与nw.exe相同的文件夹中创建一个名为“paste.vbs”的小VBscript。此文件仅模拟ctrl+v转换,以粘贴剪贴板的内容
set shell = CreateObject("WScript.Shell")
WScript.Sleep 10
shell.SendKeys "^V"
7) 运行nw.exe(使用此选项)
这是我的index.html文件
<script>
//NW gui utils
var gui = require('nw.gui');
</script>
<!DOCTYPE html>
<html>
<head>
<title>WSP Web</title>
</head>
<body>
<input type="text" id="t1"/>
<button onclick="f1()">RUN</button>
<iframe id="wsp1" src="https://web.whatsapp.com" width=100% height=700px nwdisable nwfaketop></iframe>
</body>
<script>
//Function to validate the OS and what command need to be used
function getCommandLine() {
switch (process.platform) {
case 'darwin' : return 'open';
case 'win32' : return 'start';
case 'win64' : return 'start';
default : return 'xdg-open';
}
}
//Function that call the VBScrip
function Paste(){
var sys = require('util');
var exec = require('child_process').exec;
//Run the VBScript
exec(getCommandLine() + ' ' + "paste.vbs");
}
//Main Function
function f1(){
var iframe= document.getElementById("wsp1").contentWindow;
//Focus the text input
var evt1 = new CustomEvent('focus', {'view': window,'bubbles': true,'cancelable': true});
iframe.document.getElementById("input-chatlist-search").dispatchEvent(evt1);
//Put the name of your contact in the computer clipboard (to be pasted with ctrl+v)
var clipboard = gui.Clipboard.get();
clipboard.set("your contact name", 'text');
//paste the clipboard content using the VBscript
Paste();
}
</script>
</html>
//西北gui-utils
var gui=require('nw.gui');
WSP网络
跑
//函数来验证操作系统以及需要使用的命令
函数getCommandLine(){
交换机(进程平台){
案例“darwin”:返回“open”;
案例“win32”:返回“start”;
案例“win64”:返回“start”;
默认值:返回“xdg打开”;
}
}
//调用VBScrip的函数
函数粘贴(){
var sys=require('util');
var exec=require('child_process')。exec;
//运行VBScript
exec(getCommandLine()++“paste.vbs”);
}
//主要功能
函数f1(){
var iframe=document.getElementById(“wsp1”).contentWindow;
//聚焦文本输入
var evt1=new CustomEvent('focus',{'view':window,'bubbles':true,'cancelable':true});
iframe.document.getElementById(“输入聊天列表搜索”).dispatchEvent(evt1);
//将联系人的姓名放入计算机剪贴板(使用ctrl+v组合键粘贴)
var clipboard=gui.clipboard.get();
剪贴板.set(“您的联系人姓名”,“文本”);
//使用VBscript粘贴剪贴板内容
粘贴();
}
很遗憾,这不起作用;(你最终能让它工作吗?@Samul你的解决方案还在工作吗?谢谢我的朋友!!!我不太了解你做了什么。我的方法是:我在一个新窗口中打开web.whatsapp.com,然后从打开的窗口中我做所有的自动化操作(聚焦输入,设置搜索输入的值…)。我解决这个问题的唯一方法是“hack”,但它工作得很好:powershell脚本在Chrome缓存文件夹中侦听特定的文件大小。当powershell检测到该文件时,它会在当前活动窗口中按空格键,然后powershell脚本删除该文件并等待它再次出现。我编写js代码保存缓存文件的方法非常简单$(“”)attr(“src”),“”。每当我需要我的powershell脚本按空格键时,我都会执行此代码!我对其进行了测试,并且工作完美无瑕,但我认为您的替代方案更简单,您介意告诉我您是如何完成VBScript部分的吗?
C:\nwjs> nw.exe --no-sandbox
<script>
//NW gui utils
var gui = require('nw.gui');
</script>
<!DOCTYPE html>
<html>
<head>
<title>WSP Web</title>
</head>
<body>
<input type="text" id="t1"/>
<button onclick="f1()">RUN</button>
<iframe id="wsp1" src="https://web.whatsapp.com" width=100% height=700px nwdisable nwfaketop></iframe>
</body>
<script>
//Function to validate the OS and what command need to be used
function getCommandLine() {
switch (process.platform) {
case 'darwin' : return 'open';
case 'win32' : return 'start';
case 'win64' : return 'start';
default : return 'xdg-open';
}
}
//Function that call the VBScrip
function Paste(){
var sys = require('util');
var exec = require('child_process').exec;
//Run the VBScript
exec(getCommandLine() + ' ' + "paste.vbs");
}
//Main Function
function f1(){
var iframe= document.getElementById("wsp1").contentWindow;
//Focus the text input
var evt1 = new CustomEvent('focus', {'view': window,'bubbles': true,'cancelable': true});
iframe.document.getElementById("input-chatlist-search").dispatchEvent(evt1);
//Put the name of your contact in the computer clipboard (to be pasted with ctrl+v)
var clipboard = gui.Clipboard.get();
clipboard.set("your contact name", 'text');
//paste the clipboard content using the VBscript
Paste();
}
</script>
</html>