mercredi 11 novembre 2015

How can i click a span in Behat?

I am using Behat to test an third-party webshop. I have a item in the shoppingcart that i want to delete. A confirmation pop-up shows that asks me if i really want to do it. The structure of this dialog looks as following:

<div>
    <strong class="title">Remove item from shoppingcart</strong>

    <p>Are you sure you want to delete this product?</p>

    <div class="button-container">
        <span class="button" data-confirm="true">Yes</span>
        <span class="button alt right" data-mfp-close-link="true">No</span>
    </div>
</div>

I was able to select the span using xpath with the following code:

public function iConfirmTheWindow()
{
  $session = $this->getSession();
  $element = $session->getPage()->find(
  'xpath',
  $session->getSelectorsHandler()->selectorToXpath('css', 'span.button')
  );
  if (null === $element) {
  throw new \InvalidArgumentException(sprintf('Could not find confirmation window'));
  }

  $element->click();
}

The selecting works, but Behat seems to be unable to click the span.

 supports clicking on links and submit or reset buttons only. But "span" provided

I need to click this item, how can i rewrite my function so that it can be clicked?

Aucun commentaire:

Enregistrer un commentaire