Skip to content

Instantly share code, notes, and snippets.

@DavertMik
Created September 9, 2012 14:45
Show Gist options
  • Save DavertMik/3684798 to your computer and use it in GitHub Desktop.
Save DavertMik/3684798 to your computer and use it in GitHub Desktop.
XPath dsl in Codeception RFC
<?php
XPath::descendant('p')[1]; //
XPath::descendant('p', array('@id' => 'xxx')); // .//p[@id = 'foo']
XPath::descendant('a', array('href'))->OR(XPath::attrEquals('id', $locator), XPath::contains($locator), XPath::descendant('img')->attrContains('alt', $locator));
XPath::descendant('input', array('type' => 'radio'));
XPath::descendant('table')->or(array('id' => $locator, XPath::descendant('caption')->contains($locator));
// .//input[@id=//label[contains(.,'My Label')]/@for]
XPath::descendant('input')->attrEquals('id', XPath::anywhere('label')->contains($label)->attr('for'));
// alternative syntax
XPath::find('input')->first();
XPath::find('input')[5];
XPath::find('select')->children('option', array('selcted'))->equals('Option #1');
XPath::find('input')->attrEquals('id', XPath::findAll('label')->contains($label)->attr('for'));
XPath::or(Xpath::find('input', array('type' => 'text')), XPath::find('textarea'));
// or
XPath::combine(Xpath::find('input', array('type' => 'text')), XPath::find('textarea'));
//book[normalize-space(@isbn)=”ISBN”]
XPath::findAll('book')->attrEquals(XPath::trim('isbn'), 'ISBN');
// //*[count(author)=2]
XPath::findAll()->count('author', 2);
// //*[count(author)>2]
XPath::findAll()->countMoreThen('author',2);
// //*[count(author)<2]
XPath::findAll()->countLessThen('author',2);
// //*[starts-with(.,'auth')]
XPath::findAll()->startsWith('auth');
// //*[string-length(@name) = 5]
XPath::findAll()->attrEquals(XPath::stringLength(XPath::trim('name')), 5);
// //*[string-length(name()) = 5]
XPath::findAll()->equals(XPath::stringLength('name()'), 5);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment