网络驱动程序返回的值 [英] Values returned by webdrivers

查看:23
本文介绍了网络驱动程序返回的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用 POST/session/{session id}/element 执行搜索后,我从 Chrome 网络驱动程序中得到:

After performing a search using POST /session/{session id}/element, I get this from the Chrome webdriver:

{ sessionId: '3241e7da289f4feb19c1f55dfc87024b',
  status: 0,
  value: { ELEMENT: '0.12239552668870868-1' } }

这是规范的要求吗?

我之所以这么问是因为我在任何地方都找不到用大写字母清楚地表示ELEMENT"的地方.我在规范中所能找到的只是设置了一个名为 value 的键(它是:它被设置为 { ELEMENT: '0.12239552668870868-1' }

I am asking because I couldn't find anywhere a spot where it said clearly "ELEMENT" in capital letters. All I can find in the specs is that a key called value is set (which it is: it's set as { ELEMENT: '0.12239552668870868-1' }

  • 我可以一直期待其他浏览器的网络驱动程序的响应吗?也就是说,总是返回 statussessionId 吗?

那是 { ELEMENT: '0.12239552668870868-1' } 铬构成对象的方式吗?或者对于任何网络驱动程序都是如此?不是,其他网络驱动程序返回什么?

Is that { ELEMENT: '0.12239552668870868-1' } the way chromium makes up the object? Or is this true for any webdrivers? Of not, what do other webdrivers return?

推荐答案

WebDriver-W3C Candidate Recommendation 明确提到以下几点:

  • Find Element 命令用于在当前浏览上下文中查找可用于未来命令的元素.
  • 让位置策略成为获得名为using"的属性的结果.
  • 让选择器成为获取名为value"的属性的结果.
  • 获取带有参数名称的属性的结果定义为与调用Object的结果相同.GetOwnProperty(propertyName).
  • GetOwnProperty(propertyName)ECMAScript® 语言规范 定义为:
  • The Find Element command is used to find an element in the current browsing context that can be used for future commands.
  • Let location strategy be the result of getting a property called "using".
  • Let selector be the result of getting a property called "value".
  • The result of getting a property with argument name is defined as being the same as the result of calling Object.GetOwnProperty(propertyName).
  • GetOwnProperty(propertyName) in ECMAScript® Language Specification is defined as :

字符串对象使用 GetOwnProperty 用于其他原生 ECMAScript 对象的内部方法.这个特殊的内部方法提供了对与 String 对象的各个字符相对应的命名属性的访问.

String objects use a variation of the GetOwnProperty internal method used for other native ECMAScript objects. This special internal method provides access to named properties corresponding to the individual characters of String objects.

  • 因此调用 GetOwnProperty 是内部方法用于其他原生 ECMAScript 对象,并在 Browser DriversBrowser Clients 的内部范围内解析.
  • Mozilla 有很好的文档记录 Object.getOwnPropertyNames()getOwnPropertyDescriptors().
    • So invoking GetOwnProperty are internal method used for other native ECMAScript objects and are resolved within the internal scope of the Browser Drivers and Browser Clients.
    • Mozilla have well documented Object.getOwnPropertyNames() and getOwnPropertyDescriptors().
    • 我使用您通过 Google 主页搜索框 提供的所有信息进行了一个小测试,即 https://www.google.co.在中包含WebDrivers的所有主要变体,结果如下:

      I did a small test with all the info you have provided with Search Box of Google Home Page i.e. https://www.google.co.in with all the major variants of WebDrivers and here is the result :

      • ChromeDriver - OSS :

      • ChromeDriver - OSS :

      [[ChromeDriver: chrome on XP (0d24fd038bde751b1e411711271c3e69)] -> name: q]
      [[ChromeDriver: chrome on XP (0d24fd038bde751b1e411711271c3e69)] -> name: q]
      

    • FirefoxDriver - W3C :

    • FirefoxDriver - W3C :

      [[FirefoxDriver: firefox on XP (e7a56813-97c5-466e-9c35-24c9f89af6ed)] -> name: q]
      [[FirefoxDriver: firefox on XP (e7a56813-97c5-466e-9c35-24c9f89af6ed)] -> name: q]
      

    • InternetExplorerDriver - W3C :

    • InternetExplorerDriver - W3C :

      [[InternetExplorerDriver: internet explorer on WINDOWS (367257db-cdbc-4be7-aeac-805a21ad9d2d)] -> name: q]
      [[InternetExplorerDriver: internet explorer on WINDOWS (367257db-cdbc-4be7-aeac-805a21ad9d2d)] -> name: q]
      

    • 因此,您可以从相关 value 字段的字段详细信息中观察到返回的模式类似,直到 WebDriver 变体将正确的引用传递给用户它应该'不要成为障碍.

      So as you can observe from the field details of the concerned value field returned is in similar pattern and till the WebDriver variant passes the correct reference to user it shouldn't be a obstacle.

      最后,此时值得一提的是,像 FirefoxDriverInternetExplorerDriver(均符合 W3C 标准),ChromeDriver 是几乎W3C 兼容,并且可能会在一些功能方面有所不同.

      Finally, it is worth to mention at this point of time that like FirefoxDriver and InternetExplorerDriver (both being W3C compliant), ChromeDriver is almost W3C compliant and may vary from a few functional aspects.

      根据您的问题和更新,您对 ChromeDriverChrome 通信协议非常正确.更细化我们可以发现 webdriver 调用的一些不同之处,如下所示:

      As per your question and update, you are pretty right about ChromeDriver and Chrome communication protocol. Getting more granular we can find some difference in the webdriver call as follows :

      • 火狐:

      1516626575533   webdriver::server   DEBUG   <- 200 OK {"value":{"element-6066-11e4-a52e-4f735466cecf":"6e35faa4-233f-400c-a6c7-6a66b54a69e5"}}
      

      因此,Firefox 浏览器返回:

      So, Firefox Browser returns :

      "value":{"element-6066-11e4-a52e-4f735466cecf":"6e35faa4-233f-400c-a6c7-6a66b54a69e5"}
      

      • 铬:

        • Chrome :

                  [14.921][DEBUG]: DEVTOOLS RESPONSE Runtime.evaluate (id=25) {
             "result": {
                "type": "object",
                "value": {
                   "status": 0,
                   "value": {
                      "ELEMENT": "0.7086986861512812-1"
                   }
                }
             }
          }
          

        • 因此,Chrome 浏览器返回:

          So, Chrome Browser returns :

          "value": {"ELEMENT": "0.7086986861512812-1"}
          

          对我们用户来说最重要的是浏览器对象返回的元素的值,该元素总是由用户引用并由 webdriver 实例正确识别.所有这些内部逻辑对最终用户来说都变成了抽象.

          What matters most to we user is the value of the element returned by the browser object which is always referred by an user and correctly identified by the webdriver instance. All these inner logic becomes abstract to the end user.

          从@FlorentB 添加一些重要字节.的评论:

          Adding some significant bytes from @FlorentB. 's comments :

          Selenium 的早期版本,即Selenium v​​2.x 使用关键字 ELEMENT 存储 DOM 树 元素的引用.此密钥在 Selenium 的最新版本(即 Selenium v​​3.x)中更改为 element-6066-11e4-a52e-4f735466ce.当前 ChromeDriver 的大部分实现仍然来自 Selenium 2.x 规范.

          The earlier versions of Selenium i.e. Selenium v2.x used the keyword ELEMENT to store the reference of a DOM Tree element. This key was changed within the recent versions of Selenium i.e. Selenium v3.x to element-6066-11e4-a52e-4f735466ce. Most of the implementation of the current ChromeDriver is still from the Selenium 2.x specifications.

          这篇关于网络驱动程序返回的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆