如果页面上没有项目,请继续脚本javascript

时间:2017-03-25 18:49:48

标签: javascript download element imacros skip

我在imacros和javascript上编写脚本。该脚本单击页面上的按钮,然后出现用于选择文件下载(pdf)的对话框。

我通过网站查看各种号码并搜索pdf文件。在脚本的过程中,当页面没有所需的项目时,可能会出现这种情况(尚未收到数据,下载文件的按钮也不会被激活)。

谁知道如何编写一个脚本,当时页面上的所需元素不会成为继续工作的脚本并将其他值输入表单然后下载文件?

for (i=1;i<=3; i++) {
var macro; // Create a variable macro
macro = "CODE:"; // Enter the code for the macro
macro += "URL GOTO=http://www.dpd.ru/ols/order/order.do2"+"\n";// Go to the website
macro += "TAG POS=1 TYPE=INPUT:TEXT ATTR=ID:datePickup CONTENT=my date"+"\n";// Set the date
macro += "TAG POS=1 TYPE=IMG ATTR=ID:filter_show"+"\n";// Advanced Search
macro += "TAG POS=1 TYPE=INPUT:TEXT ATTR=ID:orderNum CONTENT=my number"+"\n"; //Set number of dispatch
macro += "TAG POS=1 TYPE=IMG ATTR=ID:order_refresh_btn"+"\n";// Show orders
macro += "TAG POS=1 TYPE=INPUT:CHECKBOX FORM=ID:order_list_form ATTR=NAME:orderId CONTENT=YES"+"\n"; // Select document
macro += "TAG POS=1 TYPE=IMG ATTR=ID:order_delivery_proof_print_dialog_btn"+"\n"; // Printing a document
macro += "TAG POS=1 TYPE=IMG ATTR=ID:order_delivery_proof_print_form_btn"+"\n";// Download window
macro += "TAB T=2"+"\n";// Opening the second tab
macro += "TAB T=1"+"\n";// Open the tab
macro += "TAG POS=12 TYPE=SPAN ATTR=TXT:close"+"\n"; // Close download menu
iimPlay(macro) // Run the variable
}

enter image description here

1 个答案:

答案 0 :(得分:0)

我的英语不是很清楚。但根据我的理解,你希望脚本继续工作,即使元素不存在吗?如果这是您的需要,您希望在代码的开头使用“SET !ERRORIGNORE YES”命令。

更新的代码:

for (i=1;i<=3; i++) {
var macro; // Create a variable macro
macro = "CODE:"; // Enter the code for the macro
macro += "SET !ERRORIGNORE YES" + "\n"; //Set script to ignore error and continue work 
macro += "URL GOTO=http://www.dpd.ru/ols/order/order.do2"+"\n";// Go to the website
macro += "TAG POS=1 TYPE=INPUT:TEXT ATTR=ID:datePickup CONTENT=my date"+"\n";// Set the date
macro += "TAG POS=1 TYPE=IMG ATTR=ID:filter_show"+"\n";// Advanced Search
macro += "TAG POS=1 TYPE=INPUT:TEXT ATTR=ID:orderNum CONTENT=my number"+"\n"; //Set number of dispatch
macro += "TAG POS=1 TYPE=IMG ATTR=ID:order_refresh_btn"+"\n";// Show orders
macro += "TAG POS=1 TYPE=INPUT:CHECKBOX FORM=ID:order_list_form ATTR=NAME:orderId CONTENT=YES"+"\n"; // Select document
macro += "TAG POS=1 TYPE=IMG ATTR=ID:order_delivery_proof_print_dialog_btn"+"\n"; // Printing a document
macro += "TAG POS=1 TYPE=IMG ATTR=ID:order_delivery_proof_print_form_btn"+"\n";// Download window
macro += "TAB T=2"+"\n";// Opening the second tab
macro += "TAB T=1"+"\n";// Open the tab
macro += "TAG POS=12 TYPE=SPAN ATTR=TXT:close"+"\n"; // Close download menu
iimPlay(macro) // Run the variable
}

希望这是你想要的?