giorgiosironi / phpunit-selenium

Selenium RC integration for PHPUnit
http://www.phpunit.de/
Other
600 stars 271 forks source link

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

Open IAmAlmighty opened 8 years ago

IAmAlmighty commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

Ty mate I will try. =)