getMechanism()) { case 'class name': return '*['.static::fromClass($by->getValue()).']'; case 'id': return '*[@id='.static::escapeQuotes($by->getValue()).']'; case 'name': return '*[@name='.static::escapeQuotes($by->getValue()).']'; case 'link text': return 'a[string()='.static::escapeQuotes($by->getValue()).']'; case 'partial link text': return 'a[contains(string(), '.static::escapeQuotes($by->getValue()).')]'; case 'tag name': return $by->getValue(); case 'xpath': return ltrim($by->getValue(), './'); } throw new Exception('Not supported selector type "'.$by->getMechanism().'".'); } /** * Get XPath selector from class. * * @param string $class class to be converted to XPath selector * * @return string */ public static function fromClass($class) { $length = strlen(' '.$class); return '@class="'.$class.'" or contains(@class,'.static::escapeQuotes(' '.$class.' '). ') or starts-with(@class, '.static::escapeQuotes($class.' ').') or'. ' substring(@class, string-length(@class)-'.($length - 1).')='. static::escapeQuotes(' '.$class).''; } }