lundi 25 juin 2018

NightwatchJS Unable to locate element using CSS Selector

I've currently got a section of a web site that looks like so:

<form id="product_form" method="POST" action="/cart/add" role="form">
  <div class="row">
    <div class="col-md-6 col-md-offset-3">
      <div>
        <img class="product-image" src="/static/images/products/4388801543.jpg" width="500px" alt="">
      </div>
    </div>
    <div class="col-md-3 product-variants other_options">
      <h1 itemprop="name" class="product-single__title h3 uppercase">Samburu Shorts - Mens</h1>
      <p class="product-single__price product-single__price-product-template">
        <span id="ProductPrice" itemprop="price" content="$55.95">$55.95</span>
      </p>
      <input type="radio" name="variant_id" class="hidden" id="14903870471" value="14903870471" onclick="enableSubmit()"><label for="14903870471" class="option text-center  selector size-value">29x11 Sand-Grey</label>
      <input type="radio" name="variant_id" class="hidden" id="16304664135" value="16304664135" onclick="enableSubmit()"><label for="16304664135" class="option text-center  selector size-value">29x11 Aubergine-Grey</label>
      <input type="radio" name="variant_id" class="hidden" id="16304665799" value="16304665799" onclick="enableSubmit()"><label for="16304665799" class="option text-center  selector size-value">34x7-5 Sand-Grey</label>
      <div class="product-add">
        <button id="add-to-cart" class="addItemToCart btn addToCart-btn product-form__cart-submit" disabled="" type="submit">Add to Cart</button>
      </div>
      <div class="social-sharing">
        <a target="_blank" href="#" class="btn clear btn--share share-facebook" title="Share on Facebook">
        <img src="//cdn.shopify.com/s/files/1/0281/7544/t/59/assets/img_share_fb.png?3517946130637841476">
        <span class="visually-hidden">Share on Facebook</span>
        </a>
        <a target="_blank" href="#" class="btn clear btn--share share-twitter" title="Tweet on Twitter">
        <img src="//cdn.shopify.com/s/files/1/0281/7544/t/59/assets/img_share_twitter.png?3517946130637841476">
        <span class="visually-hidden">Tweet on Twitter</span>
        </a>
        <a target="_blank" href="#" class="btn clear btn--share share-pinterest" title="Pin on Pinterest">
        <img src="//cdn.shopify.com/s/files/1/0281/7544/t/59/assets/img_share_pin.png?3517946130637841476">
        <span class="visually-hidden">Pin on Pinterest</span>
        </a>
      </div>
    </div>
  </div>
</form>

I'm scripting out a test through NightwatchJS where I am trying to select one of the radio buttons so I can automate a user experience. The code test block that I have written out is as follows:

'Check that widget loaded on new product page' : function(browser) {
   browser
      .waitForElementVisible('#monsoon-inline-reco-div-ul', longWait, () => {
      })
      .elements('css selector', '#monsoon-inline-reco-div-ul li', (results) => {
         browser.assert.equal(results.value.length, 4);
      })
      .click('#product_form > div > div:nth-child(2) > input[type=radio]')
      .pause(longWait)
      .end();
  }

The line in question is the click command. I keep getting errors about how the script cannot find the element given the css selector. I've tested this in the console in the browser itself using document.querySelector('#product_form > div > div:nth-child(2) > input[type=radio]').click() and the radio button is clicked. Could use some thoughts on something I might be doing wrong because I've been working this for a couple hours now and have tried a variety of different things.

Aucun commentaire:

Enregistrer un commentaire