Xpath.php 678 B

123456789101112131415161718192021222324252627
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\TestFramework\Helper;
  7. class Xpath
  8. {
  9. /**
  10. * Get elements count for XPath
  11. *
  12. * @param string $xpath
  13. * @param string $html
  14. * @return int
  15. */
  16. public static function getElementsCountForXpath($xpath, $html)
  17. {
  18. $domDocument = new \DOMDocument('1.0', 'UTF-8');
  19. libxml_use_internal_errors(true);
  20. $domDocument->loadHTML($html);
  21. libxml_use_internal_errors(false);
  22. $domXpath = new \DOMXPath($domDocument);
  23. $nodes = $domXpath->query($xpath);
  24. return $nodes->length;
  25. }
  26. }