1
1
---
2
- title : " Working with select elements "
2
+ title : " 同选择元素一起工作 "
3
3
weight : 3
4
4
---
5
-
6
- {{% notice info %}}
7
- <i class =" fas fa-language " ></i > 页面需要从英语翻译为简体中文。
8
- 您熟悉英语与简体中文吗?帮助我们翻译它,通过 pull requests 给我们!
9
- {{% /notice %}}
10
-
11
- Select elements can require quite a bit of boiler plate code to automate.
12
- To reduce this and make your tests cleaner, there is a
13
- ` Select ` class in the Selenium support package.
14
- To use it, you will need the following import statement:
5
+
6
+ 选择元素可能需要大量样板代码才能自动化.
7
+ 为了减少这种情况并使您的测试更干净, 在Selenium的support包中有一个
8
+ ` Select ` 类.
9
+ 要使用它,您将需要以下导入语句:
15
10
16
11
{{< code-tab >}}
17
12
{{< code-panel language="java" >}}
@@ -34,8 +29,7 @@ import org.openqa.selenium.support.ui.Select
34
29
{{< / code-panel >}}
35
30
{{< / code-tab >}}
36
31
37
- You are then able to create a Select object using a WebElement that
38
- references a ` <select> ` element.
32
+ 然后,您能够参考 ` <select> ` 元素,基于WebElement创建一个Select对象。
39
33
40
34
{{< code-tab >}}
41
35
{{< code-panel language="java" >}}
@@ -63,10 +57,8 @@ val selectObject = new Select(selectElement)
63
57
{{< / code-panel >}}
64
58
{{< / code-tab >}}
65
59
66
- The Select object will now give you a series of commands
67
- that allow you to interact with a ` <select> ` element.
68
- First of all, there are different ways of selecting an option
69
- from the ` <select> ` element.
60
+ Select对象现在将为您提供一系列命令,使您可以与 ` <select> ` 元素进行交互.
61
+ 首先,有多种方法可以从 ` <select> ` 元素中选择一个选项.
70
62
71
63
``` html
72
64
<select >
@@ -76,7 +68,7 @@ from the `<select>` element.
76
68
</select >
77
69
```
78
70
79
- There are three ways to select the first option from the above element :
71
+ 有三种方法可以从上述元素中选择第一个选项 :
80
72
81
73
{{< code-tab >}}
82
74
{{< code-panel language="java" >}}
@@ -134,7 +126,7 @@ selectObject.selectByVisibleText("Bread")
134
126
{{< / code-panel >}}
135
127
{{< / code-tab >}}
136
128
137
- You can then check which options are selected by using :
129
+ 然后,您可以检视所有被选择的选项 :
138
130
139
131
{{< code-tab >}}
140
132
{{< code-panel language="java" >}}
@@ -174,8 +166,7 @@ val firstSelectedOption = selectObject.firstSelectedOption
174
166
{{< / code-tab >}}
175
167
176
168
177
- Or you may just be interested in what ` <option> ` elements
178
- the ` <select> ` element contains:
169
+ 或者您可能只对 ` <select> ` 元素包含哪些 ` <option> ` 元素感兴趣:
179
170
180
171
{{< code-tab >}}
181
172
{{< code-panel language="java" >}}
@@ -203,7 +194,7 @@ val allAvailableOptions = selectObject.options
203
194
{{< / code-panel >}}
204
195
{{< / code-tab >}}
205
196
206
- If you want to deselect any elements, you now have four options :
197
+ 如果要取消选择任何元素,现在有四个选项 :
207
198
208
199
{{< code-tab >}}
209
200
{{< code-panel language="java" >}}
@@ -276,8 +267,8 @@ selectObject.deselectAll()
276
267
{{< / code-panel >}}
277
268
{{< / code-tab >}}
278
269
279
- Finally, some ` <select> ` elements allow you to select more than one option .
280
- You can find out if your ` <select> ` element is one of these by using :
270
+ 最后,一些 ` <select> ` 元素允许您选择多个选项 .
271
+ 您可以通过使用以下命令确定您的 ` <select> ` 元素是否允许多选 :
281
272
282
273
{{< code-tab >}}
283
274
{{< code-panel language="java" >}}
0 commit comments