public function __construct(NodeElement $node, Session $session) { if (!$node->hasClass(self::NOTICE_CLASS)) { throw new \InvalidArgumentException(sprintf('Provided node does not have class %s', self::NOTICE_CLASS)); } parent::__construct($node->getXpath(), $session); }
/** * Creates Element instance based on existing NodeElement instance. * * @param NodeElement $node_element Node element. * @param IPageFactory $page_factory Page factory. * * @return static * @throws ElementException When page factory is missing. */ public static function fromNodeElement(NodeElement $node_element, IPageFactory $page_factory = null) { if (!isset($page_factory)) { throw new ElementException('Page factory is required to create this element', ElementException::TYPE_PAGE_FACTORY_REQUIRED); } $selenium_selector = array(How::XPATH => $node_element->getXpath()); return new static($selenium_selector, $page_factory); }
/** * @param NodeElement $node */ public function setNode(NodeElement $node) { $this->node = $node; $this->setXpath($node->getXpath()); $this->visible = $node->isVisible(); $id = $node->getAttribute('id'); if ($id) { $this->setId($id); } $classes = $node->getAttribute('class'); if ($classes) { $this->classes = explode(' ', $classes); } $this->attributes = self::parseAttribs($node); }
public function testGetXpath() { $node = new NodeElement('some custom xpath', $this->session); $this->assertEquals('some custom xpath', $node->getXpath()); $this->assertNotEquals('not some custom xpath', $node->getXpath()); }
/** * Creates Element instance based on existing NodeElement instance. * * @param NodeElement $node_element Node element. * @param IPageFactory $page_factory Page factory. * * @return static */ public static function fromNodeElement(NodeElement $node_element, IPageFactory $page_factory = null) { $selenium_selector = array(How::XPATH => $node_element->getXpath()); return new static($selenium_selector, $node_element->getSession()); }
/** * Drags an element on another one. * Works better than the standard dragTo. * * @param NodeElement $element * @param NodeElement $dropZone */ public function dragElementTo(NodeElement $element, NodeElement $dropZone) { $session = $this->getSession()->getDriver()->getWebDriverSession(); $from = $session->element('xpath', $element->getXpath()); $to = $session->element('xpath', $dropZone->getXpath()); $session->moveto(['element' => $from->getID()]); $session->buttondown(''); $session->moveto(['element' => $to->getID()]); $session->buttonup(''); }
/** * A bit of a hack, we require the Session to create instances of WPTableRow, so we store it here * @param NodeElement $node * @param Session $session */ public function __construct(NodeElement $node, Session $session) { parent::__construct($node->getXpath(), $session); $this->session = $session; }
/** * @param NodeElement $element * @param string $script * * @example * $this->executeJsOnElement($this->element('*', 'Meta tags'), 'return jQuery({{ELEMENT}}).text();'); * $this->executeJsOnElement($this->element('*', '#menu'), '{{ELEMENT}}.focus();'); * * @throws \Exception * * @return mixed */ public function executeJsOnElement(NodeElement $element, $script) { $session = $this->getWebDriverSession(); // We need to trigger something with "withSyn" method, because, otherwise an element won't be found. $element->focus(); $this->processJavaScript($script)->debug([$script]); return $session->execute(['script' => str_replace('{{ELEMENT}}', 'arguments[0]', $script), 'args' => [['ELEMENT' => $session->element('xpath', $element->getXpath())->getID()]]]); }