Skip to content

Commit

Permalink
Update Chinese translation of "interactions.zh-cn.md" and “elements\_…
Browse files Browse the repository at this point in the history
…index.zh-cn.md” (#929)[deploy site]
  • Loading branch information
alaahong committed Jan 16, 2022
1 parent f573262 commit 87db007
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
title: "网络元素"
linkTitle: "元素"
weight: 8
needsTranslation: true
aliases: [
"/documentation/zh-cn/webdriver/web_element/",
"/zh-cn/documentation/webdriver/web_element/"
Expand All @@ -11,4 +10,4 @@ description: >
在DOM中识别和使用元素对象.
---

The majority of most people's Selenium code involves working with web elements.
大多数人的Selenium代码都涉及使用web元素.
Original file line number Diff line number Diff line change
@@ -1,54 +1,57 @@
---
title: "Interacting with web elements"
linkTitle: "Interactions"
title: "Web元素交互"
linkTitle: "交互"
weight: 2
description: >
A high-level instruction set for manipulating form controls.
needsTranslation: true
用于操纵表单的高级指令集.
---

There are only 5 basic commands that can be executed on an element:
* [click](https://w3c.github.io/webdriver/#element-click) (applies to any element)
* [send keys](https://w3c.github.io/webdriver/#element-send-keys) (only applies to text fields and content editable elements)
* [clear](https://w3c.github.io/webdriver/#element-send-keys) (only applies to text fields and content editable elements)
* submit (only applies to form elements)
* select (see [Select List Elements](select_lists.md))

## Additional validations

These methods are designed to closely emulate a user's experience, so,
unlike the [Actions API]({{< ref "/documentation/webdriver/actions_api/" >}}), it attempts to perform two things
before attempting the specified action.
1. If it determines the element is outside the viewport, it
[scrolls the element into view](https://w3c.github.io/webdriver/#dfn-scrolls-into-view), specifically
it will align the bottom of the element with the bottom of the viewport.
2. It ensures the element is [interactable](https://w3c.github.io/webdriver/#interactability)
before taking the action. This could mean that the scrolling was unsuccessful, or that the
element is not otherwise displayed. Determining if an element is displayed on a page was too difficult to
[define directly in the webdriver specification](https://w3c.github.io/webdriver/#element-displayedness),
so Selenium sends an execute command with a JavaScript atom that checks for things that would keep
the element from being displayed. If it determines an element is not in the viewport, not displayed, not
[keyboard-interactable](https://w3c.github.io/webdriver/#dfn-keyboard-interactable), or not
[pointer-interactable](https://w3c.github.io/webdriver/#dfn-pointer-interactable),
it returns an [element not interactable](https://w3c.github.io/webdriver/#dfn-element-not-interactable) error.

## Click

The [element click command](https://w3c.github.io/webdriver/#dfn-element-click) is executed on
the [center of the element](https://w3c.github.io/webdriver/#dfn-center-point).
If the center of the element is [obscured](https://w3c.github.io/webdriver/#dfn-obscuring) for some reason,
Selenium will return an [element click intercepted](https://w3c.github.io/webdriver/#dfn-element-click-intercepted) error.

## Send keys

The [element send keys command](https://w3c.github.io/webdriver/#dfn-element-send-keys)
types the provided keys into an [editable](https://w3c.github.io/webdriver/#dfn-editable) element.
Typically, this means an element is an input element of a form with a `text` type or an element
with a`content-editable` attribute. If it is not editable,
[an invalid element state](https://w3c.github.io/webdriver/#dfn-invalid-element-state) error is returned.

[Here](https://www.w3.org/TR/webdriver/#keyboard-actions) is the list of
possible keystrokes that WebDriver Supports.
仅有五种基本命令可用于元素的操作:
* [点击](https://w3c.github.io/webdriver/#element-click) (适用于任何元素)
* [发送键位](https://w3c.github.io/webdriver/#element-send-keys) (仅适用于文本字段和内容可编辑元素)
* [清除](https://w3c.github.io/webdriver/#element-send-keys) (仅适用于文本字段和内容可编辑元素)
* 提交 (仅适用于表单元素)
* 选择 (参见 [选择列表元素](select_lists.md))

## 附加验证

这些方法的设计目的是尽量模拟用户体验, 所以,
[Actions接口]({{< ref "/documentation/webdriver/actions_api/" >}}) 不同,
在指定制定操作之前,
会尝试执行两件事.
1. 如果它确定元素在视口之外,
[则会将元素滚动到视图中](https://w3c.github.io/webdriver/#dfn-scrolls-into-view),
特别是将元素底部与视口底部对齐.
2. 确保元素在执行操作之前是[可交互的](https://w3c.github.io/webdriver/#interactability) .
这可能意味着滚动不成功,
或者该元素没有以其他方式显示.
确定某个元素是否显示在页面上太难了
[无法直接在webdriver规范中定义](https://w3c.github.io/webdriver/#element-displayedness),
因此Selenium发送一个带有JavaScript原子的执行命令,
检查是否有可能阻止该元素显示.
如果确定某个元素不在视口中, 不显示, 不可
[键盘交互](https://w3c.github.io/webdriver/#dfn-keyboard-interactable),
或不可
[指针交互](https://w3c.github.io/webdriver/#dfn-pointer-interactable),
则返回一个[元素不可交互](https://w3c.github.io/webdriver/#dfn-element-not-interactable) 错误.

## 点击

[元素点击命令](https://w3c.github.io/webdriver/#dfn-element-click) 执行在 [元素中央](https://w3c.github.io/webdriver/#dfn-center-point).
如果元素中央由于某些原因被 [遮挡](https://w3c.github.io/webdriver/#dfn-obscuring) ,
Selenium将返回一个 [元素点击中断](https://w3c.github.io/webdriver/#dfn-element-click-intercepted) 错误.

## 发送键位

[元素发送键位命令](https://w3c.github.io/webdriver/#dfn-element-send-keys)
将录入提供的键位到 [可编辑的](https://w3c.github.io/webdriver/#dfn-editable) 元素.
通常, 这意味着元素是具有 `文本` 类型的表单的输入元素或具有 `内容可编辑` 属性的元素.
如果不可编辑, 则返回
[无效元素状态](https://w3c.github.io/webdriver/#dfn-invalid-element-state) 错误.

[以下](https://www.w3.org/TR/webdriver/#keyboard-actions)
是WebDriver支持的按键列表.

{{< tabpane >}}
{{< tab header="Java" >}}
Expand Down Expand Up @@ -147,14 +150,15 @@ driver.quit()
{{< /tab >}}
{{< /tabpane >}}

## Clear
## 清除

The [element clear command](https://w3c.github.io/webdriver/#dfn-element-clear) resets the content of an element.
This requires an element to be [editable](https://w3c.github.io/webdriver/#dfn-editable),
and [resettable](https://w3c.github.io/webdriver/#dfn-resettable-elements). Typically,
this means an element is an input element of a form with a `text` type or an element
with a`content-editable` attribute. If these conditions are not met,
[an invalid element state](https://w3c.github.io/webdriver/#dfn-invalid-element-state) error is returned.
[元素清除命令](https://w3c.github.io/webdriver/#dfn-element-clear)
重置元素的内容.
这要求元素 [可编辑](https://w3c.github.io/webdriver/#dfn-editable),
[可重置](https://w3c.github.io/webdriver/#dfn-resettable-elements).
通常, 这意味着元素是具有 `文本` 类型的表单的输入元素或具有 `内容可编辑` 属性的元素.
如果不满足这些条件, 将返回
[无效元素状态](https://w3c.github.io/webdriver/#dfn-invalid-element-state) 错误.

{{< tabpane langEqualsHeader=true >}}
{{< tab header="Java" >}}
Expand Down Expand Up @@ -276,9 +280,11 @@ driver.quit()
{{< /tab >}}
{{< /tabpane >}}

## Submit
## 提交

In Selenium 4 this is no longer implemented with a separate endpoint and functions by executing a script. As
such, it is recommended not to use this method and to click the applicable form submission button instead.
在Selenium 4中,
不再通过单独的端点以及脚本执行的方法来实现.
因此, 建议不要使用此方法,
而是单击相应的表单提交按钮.


0 comments on commit 87db007

Please sign in to comment.