Webdrivers 中的元素 ID 是数字吗? [英] Are element IDs numbers in Webdrivers?

查看:25
本文介绍了Webdrivers 中的元素 ID 是数字吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在规范中似乎声明 元素ID 应该是数字.但是,Firefox 和 Chrome(在 w3c 模式下)都会返回类似 c87e08da-358e-45a8-b75c-c17cde92f606 的内容.当不在 w3c 模式下时,Chrome 会返回类似 45.32131231423424324324254245 的内容.

In the specs it seems to state that element IDs are meant to be numbers. However, both Firefox and Chrome (in w3c mode) return something like c87e08da-358e-45a8-b75c-c17cde92f606. Chrome returns something like 45.32131231423424324324254245 when NOT in w3c mode.

那么……它们是数字吗?或者,这些字符串代表数字吗?我如何将它们转换回整数?

So... are they meant to be numbers? Or, are those strings representing numbers? How do I cast them back to Integer?

推荐答案

你混淆了两种不同的东西.该规范指的是一个数字,它是页面上框架集合的索引.您的示例是 GUID,它们只是页面上引用元素的唯一标识符.两者不相同,也不能互换.

You are confusing two different things. The spec is referring to a number that is an index into the collection of frames on the page. Your examples are GUIDs that are just unique identifiers of referenced elements on the page. The two are not the same nor interchangeable.

来自您提供的链接(在 #5 下),

From the link you provided (under #5),

id 是一个 Number 对象

id is a Number object

这是在使用切换到帧的上下文中.这允许 API 接受一个数字(它是帧集合的索引)来访问一个帧.例如,在 Java 中,您将使用

This is in the context of using Switch To Frame. This allows the API to accept a number (which is an index into the collection of frames) to access a frame. For example, in Java you would use

driver.switchTo().frame(0)

其中 0id,它是一个数字对象",在您引用的规范部分中引用.这会将驱动程序上下文切换到页面上的第一个(第 0 个)帧.还有其他方法可以切换到帧,例如使用已知的网络元素.这是规范中列出的第三种方法(也在#5 下)

where 0 is the id which is a "number object" which is referred to in the portion of the spec you referenced. This would switch the driver context into the first (0th) frame on the page. There are other ways to switch to a frame, e.g. using a known web element. This is the third method listed in the spec (also under #5)

id 代表一个网页元素

id represents a web element

然后规范定义了如何处理 Web 元素的各种情况.

The spec then defines how to handle the various cases for a web element.

您在问题中引用的数字只是 GUID 或当前引用的 Web 元素的唯一标识符,如评论中描述的 FlorentB.您不能将这些数字/GUID 传递到 API 以切换帧等.

The numbers that you refer to in your question are just GUIDs or unique identifiers to currently referenced web elements as FlorentB described in comments. You can't pass these numbers/GUIDs into the API to switch frames, etc.

如果你想看看这是如何在 Java 中实现的,你可以查看文档 这里.

If you want to see how this is implemented in Java, you can see the docs here.

这篇关于Webdrivers 中的元素 ID 是数字吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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