Is there a way to set the XPath context when using XPath locators in Selenium-RC (version 2.0b3)?
I ask because I am modeling pages as objects, and have compos开发者_如何学运维ite elements ("widgets") that appear on multiple pages, so I would like to be able to refer to sub-elements within their parent widget's context.
Something like:
class SomeWidget extends Widget {
public $widget_locator;
public $element_locator = '//a[text()="something"]';
public function doSomething() {
$context = $this->widget_locator;
$selenium->click($element_locator, $context); //<-- can I do something like this?
}
}
Obviously, this is a contrived example, but the idea being that a sub-element's xpath might not be unique to the scope of the page, but is definitely unique to that widget's context.
If $context is an xpath expression, couldn't you just do $context + $element_locator
If you are talking about the usage of the PHPUnit Selenium extension, then you only can use the Selenium 1 old API. This API is still working in Selenium2/Webdriver just for backward compatibility.
So, since you are forced to use the old API (Selenium 1) the answer is NO. You cannot set the context of an element to ease the XPATHs locators.
精彩评论