Michael Smith
Michael Smith

Reputation: 409

Behat follow links with html in it

I have a response similar to

<a href="..."><span>1</span> widget</a>

and a feature like

Feature: My feature

  Scenario: My Scenario
   Given I am on the homepage
   Then I should see a "1 widget"

This will obviously fail because of the span tag. What is the proper way to assert the text is present or follow the link?

Upvotes: 0

Views: 2043

Answers (1)

Simon Westcott
Simon Westcott

Reputation: 36

You can use a regex to check the text,

Then I should see text matching "pattern"

If you're able to modify the HTML, adding a unique ID attribute to the link would be the easiest way to click it. If that's not possible, can could use a CSS selector to locate the link element and then click it. Something like this in your step (note: untested code!),

$node = $this->getSession()->getPage()->find('css', 'your css selector');
$node->click();

Upvotes: 2

Related Questions