1

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?

1
  • Might be wrong but I think the answer is "no" - a NodeElement doesn't appear to have a way to behave like a DOMAttr 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
    – Clive
    Apr 30, 2021 at 11:29

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.