public function VarbaseContext::iClickTextInTheHtmlTagElement in Varbase: The Ultimate Drupal CMS Starter Kit (Bootstrap Ready) 8.6
Same name and namespace in other branches
- 8.8 tests/features/bootstrap/VarbaseContext.php \VarbaseContext::iClickTextInTheHtmlTagElement()
- 8.4 tests/features/bootstrap/VarbaseContext.php \VarbaseContext::iClickTextInTheHtmlTagElement()
- 8.5 tests/features/bootstrap/VarbaseContext.php \VarbaseContext::iClickTextInTheHtmlTagElement()
- 8.7 tests/features/bootstrap/VarbaseContext.php \VarbaseContext::iClickTextInTheHtmlTagElement()
- 9.0.x tests/features/bootstrap/VarbaseContext.php \VarbaseContext::iClickTextInTheHtmlTagElement()
#varbase: To click on the text in the selected element.
Example 1: And I click "your text" in the "ol" element with the "class" attribute set to "breadcrumb" Example 2: And I click "your text" in the "div" element with the "id" attribute set to "right-panel"
@Then /^I click "(?P<text>[^"]*)" in the "(?P<htmlTagName>[^"]*)" element with the "(?P<attribute>[^"]*)" attribute set to "(?P<value>[^"]*)"$/
File
- tests/
features/ bootstrap/ VarbaseContext.php, line 869
Class
- VarbaseContext
- Defines application features from the specific context.
Code
public function iClickTextInTheHtmlTagElement($text, $htmlTagName, $attribute, $value) {
$elements = $this
->getSession()
->getPage()
->findAll('css', $htmlTagName);
if (empty($elements)) {
throw new \Exception(sprintf('The element "%s" was not found in the page', $htmlTagName));
}
$found = FALSE;
foreach ($elements as $element) {
$actual = $element
->getText();
$actual = preg_replace('/\\s+/u', ' ', $actual);
$regex = '/' . preg_quote($text, '/') . '/ui';
if (preg_match($regex, $actual)) {
$found = TRUE;
$element
->click();
break;
}
}
if (!$found) {
throw new \Exception(sprintf('"%s" was not found in the "%s" element', $text, $htmlTagName));
}
if (!empty($attribute)) {
$attr = $element
->getAttribute($attribute);
if (empty($attr)) {
throw new \Exception(sprintf('The "%s" attribute is not present on the element "%s"', $attribute, $htmlTagName));
}
if (strpos($attr, "{$value}") === FALSE) {
throw new \Exception(sprintf('The "%s" attribute does not equal "%s" on the element "%s"', $attribute, $value, $htmlTagName));
}
}
}