İçinde "inanzzz" kelimesini barındıran tablo satırındaki "view" linkine tıklamak için aşağıdaki örneği kullanabilirsiniz.


HTML tablo


<table>
<tr>
<td>1</td>
<td>hello</td>
<td><a href="http://www.hello.com">view</a></td>
</tr>
<tr>
<td>2</td>
<td>world</td>
<td><a href="http://www.world.com">view</a></td>
</tr>
<tr>
<td>3</td>
<td>inanzzz</td>
<td><a href="http://www.inanzzz.com">view</a></td>
</tr>
<tr>
<td>4</td>
<td>welcome</td>
<td><a href="http://www.welcome.com">view</a></td>
</tr>
</table>

Feature dosyası


Feature: Test feature

Scenario: Scenario description
Given I am on "/"
Then the response status code should be 200
And I click "view" on the row containing "inanzzz"
Then I should see "Behat"

FeatureContext.php


use Behat\MinkExtension\Context\MinkContext;

class FeatureContext extends MinkContext
{
/**
* @When /^I click "([^"]*)" on the row containing "([^"]*)"$/
*/
public function iClickOnOnTheRowContaining($linkName, $rowText)
{
/** @var $row \Behat\Mink\Element\NodeElement */
$row = $this->getSession()->getPage()->find('css', sprintf('table tr:contains("%s")', $rowText));
if (!$row) {
throw new \Exception(sprintf('Cannot find any row on the page containing the text "%s"', $rowText));
}

$row->clickLink($linkName);
}
}