In Drupal BrowserTestBase, I am trying to access an attribute value using XPath:
$query = $this->xpath('//a[text() = "View"]/@data-drupal-link-system-path');
I can't figure out any way to get the actual value.
$path = $query[0]->value;
Results in error message:
Undefined property: Behat\Mink\Element\NodeElement::$value
$path = $query[0]->getValue();
Results in error message:
Error: Call to undefined method DOMAttr::hasAttribute()
$path = $query[0]->getAttribute('data-drupal-link-system-path');
Results in error message:
Error: Call to undefined method DOMAttr::hasAttribute()
The following works, but isn't the XPath I want to use:
$query = $this->xpath('//a[text() = "View"]');
$path = $query[0]->getAttribute('data-drupal-link-system-path');
Is there any way to get at the value of an attribute from an XPath attribute query?
NodeElement
doesn't appear to have a way to behave like aDOMAttr
would, so it appears attribute selectors aren't directly supported. You could use your last (working) example with the xpath changed to$query = $this->xpath('//a[text() = "View"][@data-drupal-link-system-path]');
to get the same effect