title: Injecting javascript to click on html button
body: <p>I am attempting to inject javascript into a WKWebView in order to add an item to my cart on a website.</p>
  
  <p>I have a button:</p>
  
  <pre><code>&lt;input type="submit" name="commit" value="add to cart" class="button"&gt;
  </code></pre>
  
  <p>This is my code:</p>
  
  <pre><code>    webView.evaluateJavaScript("document.querySelector('[value=\"add to cart\"]').click();") { (result, error) in
          if error != nil {
              print("Error: ", result)
          }
      }
  //do something
  </code></pre>
  
  <p>I receive a nil error upon running this code. I have also tried inserting the type <code>submit</code> as a selector, which still resulted in nil. Is it possible that the DOM has not been loaded yet? I've attempted to fix this by adding a temporary sleep(3) before evaluating javascript, but still nothing.</p>