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

How can I get back string from element which contains selector (e.g. xpath) #379

Open
IAmAlmighty opened this issue Jun 1, 2016 · 4 comments

Comments

@IAmAlmighty
Copy link

For example I have:
$element = $this->byXPath("//body/div[@Class='some_class']");

What can I do with $element to retrieve "//body/div[@Class='some_class']" from it?

@giorgiosironi
Copy link
Owner

You get an instance of ..._Element which does not have that information. I suggest to wrap the Element in your own object, so that you can attach to it whatever data you prefer.

@IAmAlmighty
Copy link
Author

I was hoping some of intermediate object between string which we sent there and an instance of ..._Element can store that information and I just can't find it by myself.

Sad news for me because my skills now is too weak for wrap in my own object.

@giorgiosironi
Copy link
Owner

Don't be afraid of trying, you just need a new class:

class MyElement
{
    private $element;
    private $otherStuff;

    public function __construct($element, $otherStuff)
    {
        $this->element = $element;
        $this->otherStuff = $otherStuff;
    }
    // getters, other methods
}

and to create a Factory Method on some base test case:

    public function byXPathMyElement($xpath)
    {
         return new MyElement($this->byXPath($xpath), $xpath);
    }

@IAmAlmighty
Copy link
Author

Ty mate I will try. =)

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