问题描述
遇到循环问题,请参见以下示例:
// Example (This is what prints out in the console)
User Input: Hello,Stack Overflow //stored as text[]
var textbycomma = [] = text.toString().split(',');
textbycomma[] = ['Hello','Stack Overflow']
这是一个循环,用于发送用户输入的第一条消息(Hello)
,然后退出循环。
for (let k = 0; k < 2; k++) {
// I am unable to make it dynamic so let's take 2 as an example
await dmb.page.waitForSelector(
"a > div > div.Igw0E.rBNOH.YBx95.ybXk5._4EzTm.soMvl > div[class]"
);
await dmb.page.click(
"a > div > div.Igw0E.rBNOH.YBx95.ybXk5._4EzTm.soMvl > div[class]"
);
await dmb.page.waitFor(2000);
for (let i = 0; i < textbycomma.length; i++) {
let type = textbycomma[i];
await dmb.page.waitForSelector('textarea[placeholder="Message..."]');
await dmb.page.type('textarea[placeholder="Message..."]',type,{
delay: 100,});
let ig = await dmb.page.$x('//button[contains(text(),"Send")]');
await ig[0].click();
await dmb.page.waitFor(2000);
let readurls = [];
readurls[i] = dmb.page.url();
console.log(readurls);
if ((i = textbycomma.length)) {
break;
}
}
await dmb.page.goto("https://page.com/page-example");
}
await dmb.browser.close();
控制台输出:
for loop (i) = 0,0 // Prints zero both the times since it breaks out of the loop
readurls[i] = ['url1'] -- next iteration ['url2'] // it does not save url1 and url2 as a single array
我要使此node.js
脚本每隔1小时运行一次,检查数组URL并向它们发送第二条消息(Stack Overflow)
。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)