官方定位策略为webdriver [英] Official locator strategies for the webdriver
问题描述
在曾经被用于支持 Locator Strategies 目前该文档明确指出它的状态为 OBSOLETE : code> class name :返回其类名包含搜索值的元素;复合类名称是不允许的。 :返回一个匹配CSS选择器的元素。 / li>
id
:返回ID属性与搜索值匹配的元素。 b name
:返回一个元素,其NAME属性与搜索值匹配
链接文本
:返回一个可见文本与搜索值匹配的定位元素。 部分链接文本
:返回可见文本与搜索值部分匹配的定位元素。标记名称
:返回标记名称与搜索值匹配的元素。 c $ c> :返回一个匹配XPath表达式的元素。提供的XPath表达式必须按原样应用于服务器;如果表达式与元素根不相关,则服务器不应修改它。因此,XPath查询可能会返回不包含在根元素的子树中的元素。
快照:
更改通过各自的客户端特定绑定传播。对于 Selenium-Java
客户端,这里是
现在,您的问题必须是为什么 W3C规范
和 客户端
中。根据#1042 , Selenium Factory 的回答为非常直,如下所示:
这使得规格变得简单,因为这些可以使用CSS选择器来实现,它映射到querySelector / querySelectorAll。
In the official W3c webdirver documentation, it's clearly stated that the location strategies are:
State Keyword CSS selector "css selector" Link text selector "link text" Partial link text selector "partial link text" Tag name "tag name" XPath selector "xpath"
However, Selenium's wire protocol allowed:
class name css selector id name link text partial link text tag name xpath
In THEORY, Selenium's docs are obsolete and the "real" story is in the new spec document. However...
I ran some tests on the latest Chrome's own Webdriver, and I can confirm that
name
andclass name
both work; however, they are not in the specs.I remember reading on a Chromium issue that they would only ever implement the official Webdriver specs.
Now: I know the generic answer, where "specs are not always followed 100%" etc. However, what I'd like to know is:
- Can you find the code in Chromium that implements this? (link would be most welcome)
- Have there been discussions about these in the Chromium mailing list?
- Are the "unofficial" commands (which are documented in the "old" selenium specs file) likely to stay? Where did you read so?
解决方案Yes, you saw it right.
As per the current
WebDriver - W3C Candidate Recommendation
theLocator Strategies
enlisted are as follows :
"css selector"
: CSS selector"link text"
: Link text selector"partial link text"
: Partial link text selector"tag name"
: Tag name"xpath"
: XPath selectorSnapshot :
However, the
JsonWireProtocol
was once used to support the Locator Strategies enlisted below but currently the documentation clearly states it's Status as OBSOLETE :
class name
: Returns an element whose class name contains the search value; compound class names are not permitted.css selector
: Returns an element matching a CSS selector.id
: Returns an element whose ID attribute matches the search value.name
: Returns an element whose NAME attribute matches the search value.link text
: Returns an anchor element whose visible text matches the search value.partial link text
: Returns an anchor element whose visible text partially matches the search value.tag name
: Returns an element whose tag name matches the search value.xpath
: Returns an element matching an XPath expression. The provided XPath expression must be applied to the server "as is"; if the expression is not relative to the element root, the server should not modify it. Consequently, an XPath query may return elements not contained in the root element's subtree.Snapshot :
The change was propagated through the respective client specific bindings. For the
Selenium-Java
clients here is the client code where we have the switchcase working for the users :switch (using) { case "class name": toReturn.put("using", "css selector"); toReturn.put("value", "." + cssEscape(value)); break; case "id": toReturn.put("using", "css selector"); toReturn.put("value", "#" + cssEscape(value)); break; case "link text": // Do nothing break; case "name": toReturn.put("using", "css selector"); toReturn.put("value", "*[name='" + value + "']"); break; case "partial link text": // Do nothing break; case "tag name": toReturn.put("using", "css selector"); toReturn.put("value", cssEscape(value)); break; case "xpath": // Do nothing break; } return toReturn;
Snapshot :
Now, your question must be why this change in the
W3C Specs
and in theclients
. As per #1042 the Answer from the Selenium Factory was pretty straight as :
This keeps the specification simple as these can be implemented using the CSS selector, which maps down to querySelector/querySelectorAll.
这篇关于官方定位策略为webdriver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!