Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elements are not checked for existence #6

Closed
jakzal opened this issue Jul 5, 2013 · 1 comment
Closed

Elements are not checked for existence #6

jakzal opened this issue Jul 5, 2013 · 1 comment

Comments

@jakzal
Copy link
Member

jakzal commented Jul 5, 2013

InlineElement and Element instances are created without checking if the selector would return an actual html node.

Either getElement should return null, or we need a way to verify that element exists ($element->isPresent()?).

@norberttech
Copy link
Contributor

It seems that I also need it, even more than #4 :P
@jakzal what do you think about something like that

abstract class Page
{
    // ... 

    /**
     * @param string $name
     *
     * @return Element
     */
    protected function getElement($name)
    {
        $element = isset($this->elements[$name])
            ? $this->pageFactory->createInlineElement($this->elements[$name])
            : $this->pageFactory->createElement($name);

        if (!$this->has('xpath', $element->getXpath())) {
            throw new UnexpectedPageException(sprintf('"%s" element is not available on the %s', $name, $this->getName()));
        }

        return $element;
    }

   // ...
}

This should be enough, at least for cases that I can imagine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants