function DrupalWebTestCase::clickLink
Follows a link by name.
Will click the first link found with this link text by default, or a later one if an index is given. Match is case sensitive with normalized space. The label is translated label.
If the link is discovered and clicked, the test passes. Fail otherwise.
Parameters
$label: Text between the anchor tags.
$index: Link position counting from zero.
Return value
Page contents on success, or FALSE on failure.
60 calls to DrupalWebTestCase::clickLink()
- ActionsConfigurationTestCase::testActionConfiguration in modules/
simpletest/ tests/ actions.test - Test the configuration of advanced actions through the administration interface.
- AggregatorTestCase::updateFeedItems in modules/
aggregator/ aggregator.test - Updates the feed items.
- AnnounceFeedTestInvalidJsonTestCase::testInvalidFeedResponse in modules/
announcements_feed/ tests/ announce_feed_test.test - Test the announcements feed with invalid JSON or non-existing JSON URL.
- AnnounceFeedTestSanitizationTestCase::testSanitizedFeedResponse in modules/
announcements_feed/ tests/ announce_feed_test.test - Test the announcements feed with malicious content.
- AnnounceFeedTestValidateJsonFeed::testAnnounceFeedEmpty in modules/
announcements_feed/ tests/ announce_feed_test.test - Check the status of the feed with an empty JSON feed.
File
-
modules/
simpletest/ drupal_web_test_case.php, line 3060
Class
- DrupalWebTestCase
- Test case for typical Drupal tests.
Code
protected function clickLink($label, $index = 0) {
$url_before = $this->getUrl();
$urls = $this->xpath('//a[normalize-space(text())=:label]', array(
':label' => $label,
));
if (isset($urls[$index])) {
$url_target = $this->getAbsoluteUrl($urls[$index]['href']);
$this->pass(t('Clicked link %label (@url_target) from @url_before', array(
'%label' => $label,
'@url_target' => $url_target,
'@url_before' => $url_before,
)), 'Browser');
return $this->drupalGet($url_target);
}
$this->fail(t('Link %label does not exist on @url_before', array(
'%label' => $label,
'@url_before' => $url_before,
)), 'Browser');
return FALSE;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.