Chris@0: browser->setHttpAuth($user, $password); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets the tag name of a given xpath Chris@0: * @param string $xpath Chris@0: * @return string Chris@0: * @throws DriverException Chris@0: */ Chris@0: public function getTagName($xpath) { Chris@0: $elements = $this->findElement($xpath, 1); Chris@0: return $this->browser->tagName($elements["page_id"], $elements["ids"][0]); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets the attribute value of a given element and name Chris@0: * @param string $xpath Chris@0: * @param string $name Chris@0: * @return string Chris@0: * @throws DriverException Chris@0: */ Chris@0: public function getAttribute($xpath, $name) { Chris@0: $elements = $this->findElement($xpath, 1); Chris@0: return $this->browser->attribute($elements["page_id"], $elements["ids"][0], $name); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Check if element given by xpath is visible or not Chris@0: * @param string $xpath Chris@0: * @return bool Chris@0: * @throws DriverException Chris@0: */ Chris@0: public function isVisible($xpath) { Chris@0: $elements = $this->findElement($xpath, 1); Chris@0: return $this->browser->isVisible($elements["page_id"], $elements["ids"][0]); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Drags one element to another Chris@0: * @param string $sourceXpath Chris@0: * @param string $destinationXpath Chris@0: * @throws DriverException Chris@0: */ Chris@0: public function dragTo($sourceXpath, $destinationXpath) { Chris@0: $sourceElement = $this->findElement($sourceXpath, 1); Chris@0: $destinationElement = $this->findElement($destinationXpath, 1); Chris@0: $this->browser->drag($sourceElement["page_id"], $sourceElement["ids"][0], $destinationElement["ids"][0]); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Upload a file to the browser Chris@0: * @param string $xpath Chris@0: * @param string $path Chris@0: * @throws DriverException Chris@0: */ Chris@0: public function attachFile($xpath, $path) { Chris@0: if (!file_exists($path)) { Chris@0: throw new DriverException("Wow there the file does not exist, you can not upload it"); Chris@0: } Chris@0: Chris@0: if (($realPath = realpath($path)) === false) { Chris@0: throw new DriverException("Wow there the file does not exist, you can not upload it"); Chris@0: } Chris@0: Chris@0: $element = $this->findElement($xpath, 1); Chris@0: $tagName = $this->getTagName($xpath); Chris@0: if ($tagName != "input") { Chris@0: throw new DriverException("The element is not an input element, you can not attach a file to it"); Chris@0: } Chris@0: Chris@0: $attributes = $this->getBrowser()->attributes($element["page_id"], $element["ids"][0]); Chris@0: if (!isset($attributes["type"]) || $attributes["type"] != "file") { Chris@0: throw new DriverException("The element is not an input file type element, you can not attach a file to it"); Chris@0: } Chris@0: Chris@0: $this->browser->selectFile($element["page_id"], $element["ids"][0], $realPath); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Puts the browser control inside the IFRAME Chris@0: * You own the control, make sure to go back to the parent calling this method with null Chris@0: * @param string $name Chris@0: */ Chris@0: public function switchToIFrame($name = null) { Chris@0: //TODO: check response of the calls Chris@0: if ($name === null) { Chris@0: $this->browser->popFrame(); Chris@0: return; Chris@0: } else { Chris@0: $this->browser->pushFrame($name); Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Focus on an element Chris@0: * @param string $xpath Chris@0: * @throws DriverException Chris@0: */ Chris@0: public function focus($xpath) { Chris@0: $element = $this->findElement($xpath, 1); Chris@0: $this->browser->trigger($element["page_id"], $element["ids"][0], "focus"); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Blur on element Chris@0: * @param string $xpath Chris@0: * @throws DriverException Chris@0: */ Chris@0: public function blur($xpath) { Chris@0: $element = $this->findElement($xpath, 1); Chris@0: $this->browser->trigger($element["page_id"], $element["ids"][0], "blur"); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Finds elements with specified XPath query. Chris@0: * @param string $xpath Chris@12: * @return string[] Chris@0: * @throws DriverException When the operation cannot be done Chris@0: */ Chris@12: protected function findElementXpaths($xpath) { Chris@0: $elements = $this->browser->find("xpath", $xpath); Chris@12: $nodeXPaths = array(); Chris@0: Chris@0: if (!isset($elements["ids"])) { Chris@12: return array(); Chris@0: } Chris@0: Chris@0: foreach ($elements["ids"] as $i => $elementId) { Chris@12: $nodeXPaths[] = sprintf('(%s)[%d]', $xpath, $i + 1); Chris@0: } Chris@12: return $nodeXPaths; Chris@0: } Chris@0: Chris@0: }