@@ -3,17 +3,12 @@ title: "Trabajando con elementos select"
3
3
weight : 3
4
4
---
5
5
6
- {{% notice info %}}
7
- <i class =" fas fa-language " ></i > Page being translated from
8
- English to Spanish. Do you speak Spanish? Help us to translate
9
- it by sending us pull requests!
10
- {{% /notice %}}
11
6
12
-
13
- Select elements can require quite a bit of boiler plate code to automate .
14
- To reduce this and make your tests cleaner, there is a
15
- ` Select ` class in the Selenium support package .
16
- To use it, you will need the following import statement :
7
+ A la hora de seleccionar elementos puede ser necesario código repetitivo
8
+ para poder ser automatizado .
9
+ Para reducir esto y hacer tus test mas limpios, existe un clase _ Select _ en los
10
+ paquetes de soporte de Selenium.
11
+ Para usarla, necesitarás importarla de la siguiente forma :
17
12
18
13
{{< code-tab >}}
19
14
{{< code-panel language="java" >}}
@@ -29,15 +24,15 @@ using OpenQA.Selenium.Support.UI
29
24
include Selenium::WebDriver::Support
30
25
{{< / code-panel >}}
31
26
{{< code-panel language="javascript" >}}
32
- // We don't have a JavaScript code sample yet - Help us out and raise a PR
27
+ // No disponemos del ejemplo de código en Javascript aun - Ayudanos a ello abriendo un PR
33
28
{{< / code-panel >}}
34
29
{{< code-panel language="kotlin" >}}
35
30
import org.openqa.selenium.support.ui.Select
36
31
{{< / code-panel >}}
37
32
{{< / code-tab >}}
38
33
39
- You are then able to create a Select object using a WebElement that
40
- references a ` <select> ` element .
34
+ Una vez importado, ya podrás crear un objeto _ Select _ usando un WebElement que
35
+ referencie a un elemento ` <select> ` .
41
36
42
37
{{< code-tab >}}
43
38
{{< code-panel language="java" >}}
@@ -57,18 +52,18 @@ select_element = driver.find_element(id: 'selectElementID')
57
52
select_object = Select(select_element)
58
53
{{< / code-panel >}}
59
54
{{< code-panel language="javascript" >}}
60
- // We don't have a JavaScript code sample yet - Help us out and raise a PR
55
+ // No disponemos del ejemplo de código en Javascript aun - Ayudanos a ello abriendo un PR
61
56
{{< / code-panel >}}
62
57
{{< code-panel language="kotlin" >}}
63
58
val selectElement = driver.findElement(By.id("selectElementID"))
64
59
val selectObject = new Select(selectElement)
65
60
{{< / code-panel >}}
66
61
{{< / code-tab >}}
67
62
68
- The Select object will now give you a series of commands
69
- that allow you to interact with a ` <select> ` element .
70
- First of all, there are different ways of selecting an option
71
- from the ` <select> ` element .
63
+ El objeto _ Select _ te proporcionará una serie de comandos que te permitirán
64
+ interactuar con los elementos ` <select> ` .
65
+ Lo primero de todo, existen diferentes formas de seleccionar una opción de un
66
+ elemento ` <select> ` .
72
67
73
68
``` html
74
69
<select >
@@ -78,208 +73,210 @@ from the `<select>` element.
78
73
</select >
79
74
```
80
75
81
- There are three ways to select the first option from the above element:
76
+ Existen tres formas de seleccionar la primera opción del ejemplo que se muestra
77
+ arriba.
82
78
83
79
{{< code-tab >}}
84
80
{{< code-panel language="java" >}}
85
- // Select an <option > based upon the < select > element's internal index
81
+ // Selecciona una <option > basándose en el indice interno del elemento < select >
86
82
selectObject.selectByIndex(1);
87
83
88
- // Select an <option > based upon its value attribute
84
+ // Selecciona una <option > basándose en su atributo value
89
85
selectObject.selectByValue("value1");
90
86
91
- // Select an <option > based upon its text
87
+ // Selecciona una <option > basándose en el texto que muestra
92
88
selectObject.selectByVisibleText("Bread");
93
89
{{< / code-panel >}}
94
90
{{< code-panel language="python" >}}
95
- # Select an <option > based upon the < select > element's internal index
91
+ # Selecciona una <option > basándose en el indice interno del elemento < select >
96
92
select_object.select_by_index(1)
97
93
98
- # Select an <option > based upon its value attribute
94
+ # Selecciona una <option > basándose en su atributo value
99
95
select_object.select_by_value('value1')
100
96
101
- # Select an <option > based upon its text
97
+ # Selecciona una <option > basándose en el texto que muestra
102
98
select_object.select_by_visible_text('Bread')
103
99
{{< / code-panel >}}
104
100
{{< code-panel language="csharp" >}}
105
- // Select an <option > based upon the < select > element's internal index
101
+ // Selecciona una <option > basándose en el indice interno del elemento < select >
106
102
selectObject.SelectByIndex(1);
107
103
108
- // Select an <option > based upon its value attribute
104
+ // Selecciona una <option > basándose en su atributo value
109
105
selectObject.SelectByValue("value1");
110
106
111
- // Select an <option > based upon its text
112
- selectObject.SelectByText("Bread");
107
+ // Selecciona una <option > basándose en el texto que muestra
108
+ selectObject.SelectByText("Bread");
113
109
{{< / code-panel >}}
114
110
{{< code-panel language="ruby" >}}
115
- # Select an <option > based upon the < select > element's internal index
111
+ # Selecciona una <option > basándose en el indice interno del elemento < select >
116
112
select_object.select_by(: index , 1)
117
113
118
- # Select an <option > based upon its value attribute
114
+ # Selecciona una <option > basándose en su atributo value
119
115
select_object.select_by(: value , 'value1')
120
116
121
- # Select an <option > based upon its text
117
+ # Selecciona una <option > basándose en el texto que muestra
122
118
select_object.select_by(: text , 'Bread')
123
119
{{< / code-panel >}}
124
120
{{< code-panel language="javascript" >}}
125
- // We don't have a JavaScript code sample yet - Help us out and raise a PR
121
+ // No disponemos del ejemplo de código en Javascript aun - Ayudanos a ello abriendo un PR
126
122
{{< / code-panel >}}
127
123
{{< code-panel language="kotlin" >}}
128
- // Select an <option > based upon the < select > element's internal index
124
+ // Selecciona una <option > basándose en el indice interno del elemento < select >
129
125
selectObject.selectByIndex(1)
130
126
131
- // Select an <option > based upon its value attribute
127
+ // Selecciona una <option > basándose en su atributo value
132
128
selectObject.selectByValue("value1")
133
129
134
- // Select an <option > based upon its text
130
+ // Selecciona una <option > basándose en el texto que muestra
135
131
selectObject.selectByVisibleText("Bread")
136
132
{{< / code-panel >}}
137
133
{{< / code-tab >}}
138
134
139
- You can then check which options are selected by using :
135
+ Puedes revisar que opciones están seleccionadas usando :
140
136
141
137
{{< code-tab >}}
142
138
{{< code-panel language="java" >}}
143
- // Return a List< WebElement > of options that have been selected
139
+ // Devuelve una Lista de < WebElements > con las opciones que han sido seleccionadas
144
140
List<WebElement > allSelectedOptions = selectObject.getAllSelectedOptions();
145
141
146
- // Return a WebElement referencing the first selection option found by walking down the DOM
142
+ // Devuelve un WebElement que referencia a la primera opción seleccionada que se encontró en el DOM
147
143
WebElement firstSelectedOption = selectObject.getFirstSelectedOption();
148
144
{{< / code-panel >}}
149
145
{{< code-panel language="python" >}}
150
- # Return a list [ WebElement ] of options that have been selected
146
+ # Devuelve una Lista de [ WebElements ] con las opciones que han sido seleccionadas
151
147
all_selected_options = select_object.all_selected_options
152
148
153
- # Return a WebElement referencing the first selection option found by walking down the DOM
149
+ # Devuelve un WebElement que referencia a la primera opción seleccionada que se encontró en el DOM
154
150
first_selected_option = select_object.first_selected_option
155
151
{{< / code-panel >}}
156
152
{{< code-panel language="csharp" >}}
157
- // We don't have a C# code sample yet - Help us out and raise a PR
153
+ // No disponemos del ejemplo de código en C# aun - Ayudanos a ello abriendo un PR
158
154
{{< / code-panel >}}
159
155
{{< code-panel language="ruby" >}}
160
- # Return an Array[ Element ] of options that have been selected
156
+ # Devuelve un Array de < WebElements > con las opciones que han sido seleccionadas
161
157
all_selected_options = select_object.selected_options
162
158
163
- # Return a WebElement referencing the first selection option found by walking down the DOM
159
+ # Devuelve un WebElement que referencia a la primera opción seleccionada que se encontró en el DOM
164
160
first_selected_option = select_object.first_selected_option
165
161
{{< / code-panel >}}
166
162
{{< code-panel language="javascript" >}}
167
- // We don't have a JavaScript code sample yet - Help us out and raise a PR
163
+ // No disponemos del ejemplo de código en Javascript aun - Ayudanos a ello abriendo un PR
168
164
{{< / code-panel >}}
169
165
{{< code-panel language="kotlin" >}}
170
- // Return a List< WebElement > of options that have been selected
166
+ // Devuelve una Lista de < WebElements > con las opciones que han sido seleccionadas
171
167
val allSelectedOptions = selectObject.allSelectedOptions
172
168
173
- // Return a WebElement referencing the first selection option found by walking down the DOM
169
+ // Devuelve un WebElement que referencia a la primera opción seleccionada que se encontró en el DOM
174
170
val firstSelectedOption = selectObject.firstSelectedOption
175
171
{{< / code-panel >}}
176
172
{{< / code-tab >}}
177
173
178
174
179
- Or you may just be interested in what ` <option> ` elements
180
- the ` <select> ` element contains:
175
+ Tambien existe una forma de obtener que elementos ` <option> ` contiene un
176
+ ` <select> ` :
181
177
182
178
{{< code-tab >}}
183
179
{{< code-panel language="java" >}}
184
- // Return a List< WebElement > of options that the <select > element contains
180
+ // Devuelve una lista de < WebElements > que contiene las opciones de un elemento <select >
185
181
List<WebElement > allAvailableOptions = selectObject.getOptions();
186
182
{{< / code-panel >}}
187
183
{{< code-panel language="python" >}}
188
- # Return a list [ WebElement ] of options that the < ; select> ; element contains
184
+ # Devuelve una lista de [ WebElements ] que contiene las opciones de un elemento < ; select> ;
189
185
all_available_options = select_object.options
190
186
{{< / code-panel >}}
191
187
{{< code-panel language="csharp" >}}
192
- // Return a IList< IWebElement > of options that the <select > element contains
188
+ // Devuelve una IList de < IWebElements > que contiene las opciones de un elemento <select >
193
189
IList<IWebElement > allAvailableOptions = selectObject.Options;
194
190
{{< / code-panel >}}
195
191
{{< code-panel language="ruby" >}}
196
- # Return an Array [ Element ] of options that the < ; select> ; element contains
192
+ # Devuelve un array de [ WebElements ] que contiene las opciones de un elemento < ; select> ;
197
193
all_available_options = select_object.options
198
194
{{< / code-panel >}}
199
195
{{< code-panel language="javascript" >}}
200
- // We don't have a JavaScript code sample yet - Help us out and raise a PR
196
+ // No disponemos del ejemplo de código en Javascript aun - Ayudanos a ello abriendo un PR
201
197
{{< / code-panel >}}
202
198
{{< code-panel language="kotlin" >}}
203
- // Return a List< WebElement > of options that the <select > element contains
199
+ // Devuelve una lista de < WebElements > que contiene las opciones de un elemento <select >
204
200
val allAvailableOptions = selectObject.options
205
201
{{< / code-panel >}}
206
202
{{< / code-tab >}}
207
203
208
- If you want to deselect any elements, you now have four options :
204
+ A la hora de deseleccionar elementos dispones de cuatro opciones :
209
205
210
206
{{< code-tab >}}
211
207
{{< code-panel language="java" >}}
212
- // Deselect an <option > based upon the < select > element's internal index
208
+ // Deseleccionar una <option > basándose en el indice interno de un elemento < select >
213
209
selectObject.deselectByIndex(1);
214
210
215
- // Deselect an <option > based upon its value attribute
211
+ // Deseleccionar una <option > basándose en su atributo ` value `
216
212
selectObject.deselectByValue("value1");
217
213
218
- // Deselect an <option > based upon its text
214
+ // Deseleccionar una <option > basándose en el texto que muestra
219
215
selectObject.deselectByVisibleText("Bread");
220
216
221
- // Deselect all selected <option > elements
217
+ // Deseleccionar todos los elementos <option > que estan seleccionados
222
218
selectObject.deselectAll();
223
219
{{< / code-panel >}}
224
220
{{< code-panel language="python" >}}
225
- # Deselect an <option > based upon the < select > element's internal index
221
+ # Deseleccionar una <option > basándose en el indice interno de un elemento < select >
226
222
select_object.deselect_by_index(1)
227
223
228
- # Deselect an <option > based upon its value attribute
224
+ # Deseleccionar una <option > basándose en su atributo ` value `
229
225
select_object.deselect_by_value('value1')
230
226
231
- # Deselect an <option > based upon its text
227
+ # Deseleccionar una <option > basándose en el texto que muestra
232
228
select_object.deselect_by_visible_text('Bread')
233
229
234
- # Deselect all selected <option > elements
230
+ # Deseleccionar todos los elementos <option > que estan seleccionados
235
231
select_object.deselect_all()
236
232
{{< / code-panel >}}
237
233
{{< code-panel language="csharp" >}}
238
- // Deselect an <option > based upon the < select > element's internal index
234
+ // Deseleccionar una <option > basándose en el indice interno de un elemento < select >
239
235
selectObject.DeselectByIndex(1);
240
236
241
- // Deselect an <option > based upon its value attribute
237
+ // Deseleccionar una <option > basándose en su atributo ` value `
242
238
selectObject.DeselectByValue("value1");
243
239
244
- // Deselect an <option > based upon its text
240
+ // Deseleccionar una <option > basándose en el texto que muestra
245
241
selectObject.DeselectByText("Bread");
246
242
247
- // Deselect all selected <option > elements
243
+ // Deseleccionar todos los elementos <option > que estan seleccionados
248
244
selectObject.DeselectAll();
249
245
{{< / code-panel >}}
250
246
{{< code-panel language="ruby" >}}
251
- # Deselect an <option > based upon the < select > element's internal index
247
+ # Deseleccionar una <option > basándose en el indice interno de un elemento < select >
252
248
select_object.deselect_by(: index , 1)
253
249
254
- # Deselect an <option > based upon its value attribute
250
+ # Deseleccionar una <option > basándose en su atributo ` value `
255
251
select_object.deselect_by(: value , 'value1')
256
252
257
- # Deselect an <option > based upon its text
253
+ # Deseleccionar una <option > basándose en el texto que muestra
258
254
select_object.deselect_by(: text , 'Bread')
259
255
260
- # Deselect all selected <option > elements
256
+ # Deseleccionar todos los elementos <option > que estan seleccionados
261
257
select_object.deselect_all
262
258
{{< / code-panel >}}
263
259
{{< code-panel language="javascript" >}}
264
- // We don't have a JavaScript code sample yet - Help us out and raise a PR
260
+ // No disponemos del ejemplo de código en Javascript aun - Ayudanos a ello abriendo un PR
265
261
{{< / code-panel >}}
266
262
{{< code-panel language="kotlin" >}}
267
- // Deselect an <option > based upon the < select > element's internal index
263
+ // Deseleccionar una <option > basándose en el indice interno de un elemento < select >
268
264
selectObject.deselectByIndex(1)
269
265
270
- // Deselect an <option > based upon its value attribute
266
+ // Deseleccionar una <option > basándose en su atributo ` value `
271
267
selectObject.deselectByValue("value1")
272
268
273
- // Deselect an <option > based upon its text
269
+ // Deseleccionar una <option > basándose en el texto que muestra
274
270
selectObject.deselectByVisibleText("Bread")
275
271
276
- // Deselect all selected <option > elements
272
+ // Deseleccionar todos los elementos <option > que estan seleccionados
277
273
selectObject.deselectAll()
278
274
{{< / code-panel >}}
279
275
{{< / code-tab >}}
280
276
281
- Finally, some ` <select> ` elements allow you to select more than one option.
282
- You can find out if your ` <select> ` element is one of these by using:
277
+ Finalmente, existen algunos elementos ` <select> ` que te permiten seleccionar
278
+ mas de una opción.
279
+ Puedes comprobar si tu elemento ` <select> ` es uno de estos usando:
283
280
284
281
{{< code-tab >}}
285
282
{{< code-panel language="java" >}}
@@ -295,7 +292,7 @@ bool doesThisAllowMultipleSelections = selectObject.IsMultiple;
295
292
does_this_allow_multiple_selections = select_object.multiple?
296
293
{{< / code-panel >}}
297
294
{{< code-panel language="javascript" >}}
298
- // We don't have a JavaScript code sample yet - Help us out and raise a PR
295
+ // No disponemos del ejemplo de código en Javascript aun - Ayudanos a ello abriendo un PR
299
296
{{< / code-panel >}}
300
297
{{< code-panel language="kotlin" >}}
301
298
val doesThisAllowMultipleSelections = selectObject.isMultiple
0 commit comments