title: Continue the script if there is no item on the page javascript
body: <p>I'm writing a script on imacros and javascript. The script clicks on the buttons on the page, after which the dialog box for selecting the file download (pdf) appears.</p>
  
  <p>I check various numbers through the site and search for them a pdf file. In the process of the script, the situation may arise when the page does not have the desired item (the data has not yet been received and the button for downloading the file will not be active).</p>
  
  <p>Who knows how to write a script that at that moment when the desired element on the page does not turn out to be a script that continued to work and took other values ​​to enter into the form to then download the file?</p>
  
  <pre><code>for (i=1;i&lt;=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
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/1ChD2.jpg" rel="nofollow noreferrer">enter image description here</a></p>