1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688# class: Locator
* since: v1.14
Locators are the central piece of Playwright's auto-waiting and retry-ability. In a nutshell, locators represent
a way to find element(s) on the page at any moment. A locator can be created with the [`method: Page.locator`] method.
[Learn more about locators](../locators.md).
## async method: Locator.all
* since: v1.29
- returns: <[Array]<[Locator]>>
When the locator points to a list of elements, this returns an array of locators, pointing to their respective elements.
:::note
[`method: Locator.all`] does not wait for elements to match the locator, and instead immediately returns whatever is present in the page.
When the list of elements changes dynamically, [`method: Locator.all`] will produce unpredictable and flaky results.
When the list of elements is stable, but loaded dynamically, wait for the full list to finish loading before calling [`method: Locator.all`].
:::
**Usage**
```js
for (const li of await page.getByRole('listitem').all())
await li.click();
```
```python async
for li in await page.get_by_role('listitem').all():
await li.click();
```
```python sync
for li in page.get_by_role('listitem').all():
li.click();
```
```java
for (Locator li : page.getByRole("listitem").all())
li.click();
```
```csharp
foreach (var li in await page.GetByRole("listitem").AllAsync())
await li.ClickAsync();
```
## async method: Locator.allInnerTexts
* since: v1.14
- returns: <[Array]<[string]>>
Returns an array of `node.innerText` values for all matching nodes.
:::warning[Asserting text]
If you need to assert text on the page, prefer [`method: LocatorAssertions.toHaveText`] with [`option: LocatorAssertions.toHaveText.useInnerText`] option to avoid flakiness. See [assertions guide](../test-assertions.md) for more details.
:::
**Usage**
```js
const texts = await page.getByRole('link').allInnerTexts();
```
```python async
texts = await page.get_by_role("link").all_inner_texts()
```
```python sync
texts = page.get_by_role("link").all_inner_texts()
```
```java
String[] texts = page.getByRole(AriaRole.LINK).allInnerTexts();
```
```csharp
var texts = await page.GetByRole(AriaRole.Link).AllInnerTextsAsync();
```
## async method: Locator.allTextContents
* since: v1.14
- returns: <[Array]<[string]>>
Returns an array of `node.textContent` values for all matching nodes.
:::warning[Asserting text]
If you need to assert text on the page, prefer [`method: LocatorAssertions.toHaveText`] to avoid flakiness. See [assertions guide](../test-assertions.md) for more details.
:::
**Usage**
```js
const texts = await page.getByRole('link').allTextContents();
```
```python async
texts = await page.get_by_role("link").all_text_contents()
```
```python sync
texts = page.get_by_role("link").all_text_contents()
```
```java
String[] texts = page.getByRole(AriaRole.LINK).allTextContents();
```
```csharp
var texts = await page.GetByRole(AriaRole.Link).AllTextContentsAsync();
```
## method: Locator.and
* since: v1.34
* langs:
- alias-python: and_
- returns: <[Locator]>
Creates a locator that matches both this locator and the argument locator.
**Usage**
The following example finds a button with a specific title.
```js
const button = page.getByRole('button').and(page.getByTitle('Subscribe'));
```
```java
Locator button = page.getByRole(AriaRole.BUTTON).and(page.getByTitle("Subscribe"));
```
```python async
button = page.get_by_role("button").and_(page.get_by_title("Subscribe"))
```
```python sync
button = page.get_by_role("button").and_(page.get_by_title("Subscribe"))
```
```csharp
var button = page.GetByRole(AriaRole.Button).And(page.GetByTitle("Subscribe"));
```
### param: Locator.and.locator
* since: v1.34
- `locator` <[Locator]>
Additional locator to match.
## async method: Locator.ariaSnapshot
* since: v1.49
- returns: <[string]>
Captures the aria snapshot of the given element.
Read more about [aria snapshots](../aria-snapshots.md) and [`method: LocatorAssertions.toMatchAriaSnapshot`] for the corresponding assertion.
**Usage**
```js
await page.getByRole('link').ariaSnapshot();
```
```java
page.getByRole(AriaRole.LINK).ariaSnapshot();
```
```python async
await page.get_by_role("link").aria_snapshot()
```
```python sync
page.get_by_role("link").aria_snapshot()
```
```csharp
await page.GetByRole(AriaRole.Link).AriaSnapshotAsync();
```
**Details**
This method captures the aria snapshot of the given element. The snapshot is a string that represents the state of the element and its children.
The snapshot can be used to assert the state of the element in the test, or to compare it to state in the future.
The ARIA snapshot is represented using [YAML](https://yaml.org/spec/1.2.2/) markup language:
* The keys of the objects are the roles and optional accessible names of the elements.
* The values are either text content or an array of child elements.
* Generic static text can be represented with the `text` key.
Below is the HTML markup and the respective ARIA snapshot:
```html
<ul aria-label="Links">
<li><a href="/">Home</a></li>
<li><a href="/about">About</a></li>
<ul>
```
```yml
- list "Links":
- listitem:
- link "Home"
- listitem:
- link "About"
```
### option: Locator.ariaSnapshot.timeout = %%-input-timeout-%%
* since: v1.49
### option: Locator.ariaSnapshot.timeout = %%-input-timeout-js-%%
* since: v1.49
## async method: Locator.blur
* since: v1.28
Calls [blur](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/blur) on the element.
### option: Locator.blur.timeout = %%-input-timeout-%%
* since: v1.28
### option: Locator.blur.timeout = %%-input-timeout-js-%%
* since: v1.28
## async method: Locator.boundingBox
* since: v1.14
- returns: <[null]|[Object]>
- `x` <[float]> the x coordinate of the element in pixels.
- `y` <[float]> the y coordinate of the element in pixels.
- `width` <[float]> the width of the element in pixels.
- `height` <[float]> the height of the element in pixels.
This method returns the bounding box of the element matching the locator, or `null` if the element is not visible. The bounding box is
calculated relative to the main frame viewport - which is usually the same as the browser window.
**Details**
Scrolling affects the returned bounding box, similarly to
[Element.getBoundingClientRect](https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect). That
means `x` and/or `y` may be negative.
Elements from child frames return the bounding box relative to the main frame, unlike the
[Element.getBoundingClientRect](https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect).
Assuming the page is static, it is safe to use bounding box coordinates to perform input. For example, the following
snippet should click the center of the element.
**Usage**
```js
const box = await page.getByRole('button').boundingBox();
await page.mouse.click(box.x + box.width / 2, box.y + box.height / 2);
```
```java
BoundingBox box = page.getByRole(AriaRole.BUTTON).boundingBox();
page.mouse().click(box.x + box.width / 2, box.y + box.height / 2);
```
```python async
box = await page.get_by_role("button").bounding_box()
await page.mouse.click(box["x"] + box["width"] / 2, box["y"] + box["height"] / 2)
```
```python sync
box = page.get_by_role("button").bounding_box()
page.mouse.click(box["x"] + box["width"] / 2, box["y"] + box["height"] / 2)
```
```csharp
var box = await page.GetByRole(AriaRole.Button).BoundingBoxAsync();
await page.Mouse.ClickAsync(box.X + box.Width / 2, box.Y + box.Height / 2);
```
### option: Locator.boundingBox.timeout = %%-input-timeout-%%
* since: v1.14
### option: Locator.boundingBox.timeout = %%-input-timeout-js-%%
* since: v1.14
## async method: Locator.check
* since: v1.14
Ensure that checkbox or radio element is checked.
**Details**
Performs the following steps:
1. Ensure that element is a checkbox or a radio input. If not, this method throws. If the element is already
checked, this method returns immediately.
1. Wait for [actionability](../actionability.md) checks on the element, unless [`option: force`] option is set.
1. Scroll the element into view if needed.
1. Use [`property: Page.mouse`] to click in the center of the element.
1. Ensure that the element is now checked. If not, this method throws.
If the element is detached from the DOM at any moment during the action, this method throws.
When all steps combined have not finished during the specified [`option: timeout`], this method throws a
[TimeoutError]. Passing zero timeout disables this.
**Usage**
```js
await page.getByRole('checkbox').check();
```
```java
page.getByRole(AriaRole.CHECKBOX).check();
```
```python async
await page.get_by_role("checkbox").check()
```
```python sync
page.get_by_role("checkbox").check()
```
```csharp
await page.GetByRole(AriaRole.Checkbox).CheckAsync();
```
### option: Locator.check.position = %%-input-position-%%
* since: v1.14
### option: Locator.check.force = %%-input-force-%%
* since: v1.14
### option: Locator.check.noWaitAfter = %%-input-no-wait-after-removed-%%
* since: v1.14
### option: Locator.check.timeout = %%-input-timeout-%%
* since: v1.14
### option: Locator.check.timeout = %%-input-timeout-js-%%
* since: v1.14
### option: Locator.check.trial = %%-input-trial-%%
* since: v1.14
## async method: Locator.clear
* since: v1.28
Clear the input field.
**Details**
This method waits for [actionability](../actionability.md) checks, focuses the element, clears it and triggers an `input` event after clearing.
If the target element is not an `<input>`, `<textarea>` or `[contenteditable]` element, this method throws an error. However, if the element is inside the `<label>` element that has an associated [control](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control), the control will be cleared instead.
**Usage**
```js
await page.getByRole('textbox').clear();
```
```java
page.getByRole(AriaRole.TEXTBOX).clear();
```
```python async
await page.get_by_role("textbox").clear()
```
```python sync
page.get_by_role("textbox").clear()
```
```csharp
await page.GetByRole(AriaRole.Textbox).ClearAsync();
```
### option: Locator.clear.force = %%-input-force-%%
* since: v1.28
### option: Locator.clear.noWaitAfter = %%-input-no-wait-after-removed-%%
* since: v1.28
### option: Locator.clear.timeout = %%-input-timeout-%%
* since: v1.28
### option: Locator.clear.timeout = %%-input-timeout-js-%%
* since: v1.28
## async method: Locator.click
* since: v1.14
Click an element.
**Details**
This method clicks the element by performing the following steps:
1. Wait for [actionability](../actionability.md) checks on the element, unless [`option: force`] option is set.
1. Scroll the element into view if needed.
1. Use [`property: Page.mouse`] to click in the center of the element, or the specified [`option: position`].
1. Wait for initiated navigations to either succeed or fail, unless [`option: noWaitAfter`] option is set.
If the element is detached from the DOM at any moment during the action, this method throws.
When all steps combined have not finished during the specified [`option: timeout`], this method throws a
[TimeoutError]. Passing zero timeout disables this.
**Usage**
Click a button:
```js
await page.getByRole('button').click();
```
```java
page.getByRole(AriaRole.BUTTON).click();
```
```python async
await page.get_by_role("button").click()
```
```python sync
page.get_by_role("button").click()
```
```csharp
await page.GetByRole(AriaRole.Button).ClickAsync();
```
Shift-right-click at a specific position on a canvas:
```js
await page.locator('canvas').click({
button: 'right',
modifiers: ['Shift'],
position: { x: 23, y: 32 },
});
```
```java
page.locator("canvas").click(new Locator.ClickOptions()
.setButton(MouseButton.RIGHT)
.setModifiers(Arrays.asList(KeyboardModifier.SHIFT))
.setPosition(23, 32));
```
```python async
await page.locator("canvas").click(
button="right", modifiers=["Shift"], position={"x": 23, "y": 32}
)
```
```python sync
page.locator("canvas").click(
button="right", modifiers=["Shift"], position={"x": 23, "y": 32}
)
```
```csharp
await page.Locator("canvas").ClickAsync(new() {
Button = MouseButton.Right,
Modifiers = new[] { KeyboardModifier.Shift },
Position = new Position { X = 0, Y = 0 }
});
```
### option: Locator.click.button = %%-input-button-%%
* since: v1.14
### option: Locator.click.clickCount = %%-input-click-count-%%
* since: v1.14
### option: Locator.click.delay = %%-input-down-up-delay-%%
* since: v1.14
### option: Locator.click.position = %%-input-position-%%
* since: v1.14
### option: Locator.click.modifiers = %%-input-modifiers-%%
* since: v1.14
### option: Locator.click.force = %%-input-force-%%
* since: v1.14
### option: Locator.click.noWaitAfter = %%-input-no-wait-after-%%
* since: v1.14
### option: Locator.click.timeout = %%-input-timeout-%%
* since: v1.14
### option: Locator.click.timeout = %%-input-timeout-js-%%
* since: v1.14
### option: Locator.click.trial = %%-input-trial-with-modifiers-%%
* since: v1.14
### option: Locator.click.steps = %%-input-mousemove-steps-%%
* since: v1.57
## async method: Locator.count
* since: v1.14
- returns: <[int]>
Returns the number of elements matching the locator.
:::warning[Asserting count]
If you need to assert the number of elements on the page, prefer [`method: LocatorAssertions.toHaveCount`] to avoid flakiness. See [assertions guide](../test-assertions.md) for more details.
:::
**Usage**
```js
const count = await page.getByRole('listitem').count();
```
```python async
count = await page.get_by_role("listitem").count()
```
```python sync
count = page.get_by_role("listitem").count()
```
```java
int count = page.getByRole(AriaRole.LISTITEM).count();
```
```csharp
int count = await page.GetByRole(AriaRole.Listitem).CountAsync();
```
## async method: Locator.dblclick
* since: v1.14
* langs:
- alias-csharp: DblClickAsync
Double-click an element.
**Details**
This method double clicks the element by performing the following steps:
1. Wait for [actionability](../actionability.md) checks on the element, unless [`option: force`] option is set.
1. Scroll the element into view if needed.
1. Use [`property: Page.mouse`] to double click in the center of the element, or the specified [`option: position`].
If the element is detached from the DOM at any moment during the action, this method throws.
When all steps combined have not finished during the specified [`option: timeout`], this method throws a
[TimeoutError]. Passing zero timeout disables this.
:::note
`element.dblclick()` dispatches two `click` events and a single `dblclick` event.
:::
### option: Locator.dblclick.button = %%-input-button-%%
* since: v1.14
### option: Locator.dblclick.delay = %%-input-down-up-delay-%%
* since: v1.14
### option: Locator.dblclick.position = %%-input-position-%%
* since: v1.14
### option: Locator.dblclick.modifiers = %%-input-modifiers-%%
* since: v1.14
### option: Locator.dblclick.force = %%-input-force-%%
* since: v1.14
### option: Locator.dblclick.noWaitAfter = %%-input-no-wait-after-removed-%%
* since: v1.14
### option: Locator.dblclick.timeout = %%-input-timeout-%%
* since: v1.14
### option: Locator.dblclick.timeout = %%-input-timeout-js-%%
* since: v1.14
### option: Locator.dblclick.trial = %%-input-trial-with-modifiers-%%
* since: v1.14
### option: Locator.dblclick.steps = %%-input-mousemove-steps-%%
* since: v1.57
## method: Locator.describe
* since: v1.53
- returns: <[Locator]>
Describes the locator, description is used in the trace viewer and reports.
Returns the locator pointing to the same element.
**Usage**
```js
const button = page.getByTestId('btn-sub').describe('Subscribe button');
await button.click();
```
```java
Locator button = page.getByTestId("btn-sub").describe("Subscribe button");
button.click();
```
```python async
button = page.get_by_test_id("btn-sub").describe("Subscribe button")
await button.click()
```
```python sync
button = page.get_by_test_id("btn-sub").describe("Subscribe button")
button.click()
```
```csharp
var button = Page.GetByTestId("btn-sub").Describe("Subscribe button");
await button.ClickAsync();
```
### param: Locator.describe.description
* since: v1.53
- `description` <[string]>
Locator description.
## method: Locator.description
* since: v1.57
* langs: python, java, csharp
- returns: <[null]|[string]>
Returns locator description previously set with [`method: Locator.describe`]. Returns `null` if no custom description has been set.
**Usage**
```python async
button = page.get_by_role("button").describe("Subscribe button")
print(button.description()) # "Subscribe button"
input = page.get_by_role("textbox")
print(input.description()) # None
```
```python sync
button = page.get_by_role("button").describe("Subscribe button")
print(button.description()) # "Subscribe button"
input = page.get_by_role("textbox")
print(input.description()) # None
```
```java
Locator button = page.getByRole(AriaRole.BUTTON).describe("Subscribe button");
System.out.println(button.description()); // "Subscribe button"
Locator input = page.getByRole(AriaRole.TEXTBOX);
System.out.println(input.description()); // null
```
```csharp
var button = Page.GetByRole(AriaRole.Button).Describe("Subscribe button");
Console.WriteLine(button.Description()); // "Subscribe button"
var input = Page.GetByRole(AriaRole.Textbox);
Console.WriteLine(input.Description()); // null
```
## method: Locator.description
* since: v1.57
* langs: js
- returns: <[null]|[string]>
Returns locator description previously set with [`method: Locator.describe`]. Returns `null` if no custom description has been set. Prefer [`method: Locator.toString`] for a human-readable representation, as it uses the description when available.
**Usage**
```js
const button = page.getByRole('button').describe('Subscribe button');
console.log(button.description()); // "Subscribe button"
const input = page.getByRole('textbox');
console.log(input.description()); // null
```
## async method: Locator.dispatchEvent
* since: v1.14
Programmatically dispatch an event on the matching element.
**Usage**
```js
await locator.dispatchEvent('click');
```
```java
locator.dispatchEvent("click");
```
```python async
await locator.dispatch_event("click")
```
```python sync
locator.dispatch_event("click")
```
```csharp
await locator.DispatchEventAsync("click");
```
**Details**
The snippet above dispatches the `click` event on the element. Regardless of the visibility state of the element, `click`
is dispatched. This is equivalent to calling
[element.click()](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click).
Under the hood, it creates an instance of an event based on the given [`param: type`], initializes it with
[`param: eventInit`] properties and dispatches it on the element. Events are `composed`, `cancelable` and bubble by
default.
Since [`param: eventInit`] is event-specific, please refer to the events documentation for the lists of initial
properties:
* [DeviceMotionEvent](https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent/DeviceMotionEvent)
* [DeviceOrientationEvent](https://developer.mozilla.org/en-US/docs/Web/API/DeviceOrientationEvent/DeviceOrientationEvent)
* [DragEvent](https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent)
* [Event](https://developer.mozilla.org/en-US/docs/Web/API/Event/Event)
* [FocusEvent](https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent)
* [KeyboardEvent](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent)
* [MouseEvent](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent)
* [PointerEvent](https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent)
* [TouchEvent](https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/TouchEvent)
* [WheelEvent](https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/WheelEvent)
You can also specify [JSHandle] as the property value if you want live objects to be passed into the event:
```js
const dataTransfer = await page.evaluateHandle(() => new DataTransfer());
await locator.dispatchEvent('dragstart', { dataTransfer });
```
```java
JSHandle dataTransfer = page.evaluateHandle("() => new DataTransfer()");
Map<String, Object> arg = new HashMap<>();
arg.put("dataTransfer", dataTransfer);
locator.dispatchEvent("dragstart", arg);
```
```python async
data_transfer = await page.evaluate_handle("new DataTransfer()")
await locator.dispatch_event("#source", "dragstart", {"dataTransfer": data_transfer})
```
```python sync
data_transfer = page.evaluate_handle("new DataTransfer()")
locator.dispatch_event("#source", "dragstart", {"dataTransfer": data_transfer})
```
```csharp
var dataTransfer = await page.EvaluateHandleAsync("() => new DataTransfer()");
await locator.DispatchEventAsync("dragstart", new Dictionary<string, object>
{
{ "dataTransfer", dataTransfer }
});
```
### param: Locator.dispatchEvent.type
* since: v1.14
- `type` <[string]>
DOM event type: `"click"`, `"dragstart"`, etc.
### param: Locator.dispatchEvent.eventInit
* since: v1.14
- `eventInit` ?<[EvaluationArgument]>
Optional event-specific initialization properties.
### option: Locator.dispatchEvent.timeout = %%-input-timeout-%%
* since: v1.14
### option: Locator.dispatchEvent.timeout = %%-input-timeout-js-%%
* since: v1.14
## async method: Locator.dragTo
* since: v1.18
Drag the source element towards the target element and drop it.
**Details**
This method drags the locator to another target locator or target position. It will
first move to the source element, perform a `mousedown`, then move to the target
element or position and perform a `mouseup`.
**Usage**
```js
const source = page.locator('#source');
const target = page.locator('#target');
await source.dragTo(target);
// or specify exact positions relative to the top-left corners of the elements:
await source.dragTo(target, {
sourcePosition: { x: 34, y: 7 },
targetPosition: { x: 10, y: 20 },
});
```
```java
Locator source = page.locator("#source");
Locator target = page.locator("#target");
source.dragTo(target);
// or specify exact positions relative to the top-left corners of the elements:
source.dragTo(target, new Locator.DragToOptions()
.setSourcePosition(34, 7).setTargetPosition(10, 20));
```
```python async
source = page.locator("#source")
target = page.locator("#target")
await source.drag_to(target)
# or specify exact positions relative to the top-left corners of the elements:
await source.drag_to(
target,
source_position={"x": 34, "y": 7},
target_position={"x": 10, "y": 20}
)
```
```python sync
source = page.locator("#source")
target = page.locator("#target")
source.drag_to(target)
# or specify exact positions relative to the top-left corners of the elements:
source.drag_to(
target,
source_position={"x": 34, "y": 7},
target_position={"x": 10, "y": 20}
)
```
```csharp
var source = Page.Locator("#source");
var target = Page.Locator("#target");
await source.DragToAsync(target);
// or specify exact positions relative to the top-left corners of the elements:
await source.DragToAsync(target, new()
{
SourcePosition = new() { X = 34, Y = 7 },
TargetPosition = new() { X = 10, Y = 20 },
});
```
### param: Locator.dragTo.target
* since: v1.18
- `target` <[Locator]>
Locator of the element to drag to.
### option: Locator.dragTo.force = %%-input-force-%%
* since: v1.18
### option: Locator.dragTo.noWaitAfter = %%-input-no-wait-after-removed-%%
* since: v1.18
### option: Locator.dragTo.timeout = %%-input-timeout-%%
* since: v1.18
### option: Locator.dragTo.timeout = %%-input-timeout-js-%%
* since: v1.18
### option: Locator.dragTo.trial = %%-input-trial-%%
* since: v1.18
### option: Locator.dragTo.sourcePosition = %%-input-source-position-%%
* since: v1.18
### option: Locator.dragTo.targetPosition = %%-input-target-position-%%
* since: v1.18
### option: Locator.dragTo.steps = %%-input-drag-steps-%%
* since: v1.57
## async method: Locator.elementHandle
* since: v1.14
* discouraged: Always prefer using [Locator]s and web assertions over [ElementHandle]s because latter are inherently racy.
- returns: <[ElementHandle]>
Resolves given locator to the first matching DOM element. If there are no matching elements, waits for one. If multiple elements match the locator, throws.
### option: Locator.elementHandle.timeout = %%-input-timeout-%%
* since: v1.14
### option: Locator.elementHandle.timeout = %%-input-timeout-js-%%
* since: v1.14
## async method: Locator.elementHandles
* since: v1.14
* discouraged: Always prefer using [Locator]s and web assertions over [ElementHandle]s because latter are inherently racy.
- returns: <[Array]<[ElementHandle]>>
Resolves given locator to all matching DOM elements. If there are no matching elements, returns an empty list.
## method: Locator.contentFrame
* since: v1.43
- returns: <[FrameLocator]>
Returns a [FrameLocator] object pointing to the same `iframe` as this locator.
Useful when you have a [Locator] object obtained somewhere, and later on would like to interact with the content inside the frame.
For a reverse operation, use [`method: FrameLocator.owner`].
**Usage**
```js
const locator = page.locator('iframe[name="embedded"]');
// ...
const frameLocator = locator.contentFrame();
await frameLocator.getByRole('button').click();
```
```java
Locator locator = page.locator("iframe[name=\"embedded\"]");
// ...
FrameLocator frameLocator = locator.contentFrame();
frameLocator.getByRole(AriaRole.BUTTON).click();
```
```python async
locator = page.locator("iframe[name=\"embedded\"]")
# ...
frame_locator = locator.content_frame
await frame_locator.get_by_role("button").click()
```
```python sync
locator = page.locator("iframe[name=\"embedded\"]")
# ...
frame_locator = locator.content_frame
frame_locator.get_by_role("button").click()
```
```csharp
var locator = Page.Locator("iframe[name=\"embedded\"]");
// ...
var frameLocator = locator.ContentFrame;
await frameLocator.GetByRole(AriaRole.Button).ClickAsync();
```
## async method: Locator.evaluate
* since: v1.14
- returns: <[Serializable]>
Execute JavaScript code in the page, taking the matching element as an argument.
**Details**
Returns the return value of [`param: expression`], called with the matching element as a first argument, and [`param: arg`] as a second argument.
If [`param: expression`] returns a [Promise], this method will wait for the promise to resolve and return its value.
If [`param: expression`] throws or rejects, this method throws.
**Usage**
Passing argument to [`param: expression`]:
```js
const result = await page.getByTestId('myId').evaluate((element, [x, y]) => {
return element.textContent + ' ' + x * y;
}, [7, 8]);
console.log(result); // prints "myId text 56"
```
```java
Object result = page.getByTestId("myId").evaluate("(element, [x, y]) => {\n" +
" return element.textContent + ' ' + x * y;\n" +
"}", Arrays.asList(7, 8));
System.out.println(result); // prints "myId text 56"
```
```python async
result = await page.get_by_testid("myId").evaluate("(element, [x, y]) => element.textContent + ' ' + x * y", [7, 8])
print(result) # prints "myId text 56"
```
```python sync
result = page.get_by_testid("myId").evaluate("(element, [x, y]) => element.textContent + ' ' + x * y", [7, 8])
print(result) # prints "myId text 56"
```
```csharp
var result = await page.GetByTestId("myId").EvaluateAsync<string>("(element, [x, y]) => element.textContent + ' ' + x * y)", new[] { 7, 8 });
Console.WriteLine(result); // prints "myId text 56"
```
### param: Locator.evaluate.expression = %%-evaluate-expression-%%
* since: v1.14
### param: Locator.evaluate.expression = %%-js-evaluate-pagefunction-%%
* since: v1.14
### param: Locator.evaluate.arg
* since: v1.14
- `arg` ?<[EvaluationArgument]>
Optional argument to pass to [`param: expression`].
### option: Locator.evaluate.timeout
* since: v1.14
* langs: python, java, csharp
- `timeout` <[float]>
Maximum time in milliseconds to wait for the locator before evaluating. Note that after locator is resolved, evaluation itself is not limited by the timeout. Defaults to `30000` (30 seconds). Pass `0` to disable timeout.
### option: Locator.evaluate.timeout
* since: v1.14
* langs: js
- `timeout` <[float]>
Maximum time in milliseconds to wait for the locator before evaluating. Note that after locator is resolved, evaluation itself is not limited by the timeout. Defaults to `0` - no timeout.
## async method: Locator.evaluateAll
* since: v1.14
- returns: <[Serializable]>
Execute JavaScript code in the page, taking all matching elements as an argument.
**Details**
Returns the return value of [`param: expression`], called with an array of all matching elements as a first argument, and [`param: arg`] as a second argument.
If [`param: expression`] returns a [Promise], this method will wait for the promise to resolve and return its value.
If [`param: expression`] throws or rejects, this method throws.
**Usage**
```js
const locator = page.locator('div');
const moreThanTen = await locator.evaluateAll((divs, min) => divs.length > min, 10);
```
```java
Locator locator = page.locator("div");
boolean moreThanTen = (boolean) locator.evaluateAll("(divs, min) => divs.length > min", 10);
```
```python async
locator = page.locator("div")
more_than_ten = await locator.evaluate_all("(divs, min) => divs.length > min", 10)
```
```python sync
locator = page.locator("div")
more_than_ten = locator.evaluate_all("(divs, min) => divs.length > min", 10)
```
```csharp
var locator = page.Locator("div");
var moreThanTen = await locator.EvaluateAllAsync<bool>("(divs, min) => divs.length > min", 10);
```
### param: Locator.evaluateAll.expression = %%-evaluate-expression-%%
* since: v1.14
### param: Locator.evaluateAll.expression = %%-js-evaluate-pagefunction-%%
* since: v1.14
### param: Locator.evaluateAll.arg
* since: v1.14
- `arg` ?<[EvaluationArgument]>
Optional argument to pass to [`param: expression`].
## async method: Locator.evaluateHandle
* since: v1.14
- returns: <[JSHandle]>
Execute JavaScript code in the page, taking the matching element as an argument, and return a [JSHandle] with the result.
**Details**
Returns the return value of [`param: expression`] as a[JSHandle], called with the matching element as a first argument, and [`param: arg`] as a second argument.
The only difference between [`method: Locator.evaluate`] and [`method: Locator.evaluateHandle`] is that [`method: Locator.evaluateHandle`] returns [JSHandle].
If [`param: expression`] returns a [Promise], this method will wait for the promise to resolve and return its value.
If [`param: expression`] throws or rejects, this method throws.
See [`method: Page.evaluateHandle`] for more details.
### param: Locator.evaluateHandle.expression = %%-evaluate-expression-%%
* since: v1.14
### param: Locator.evaluateHandle.expression = %%-js-evaluate-pagefunction-%%
* since: v1.14
### param: Locator.evaluateHandle.arg
* since: v1.14
- `arg` ?<[EvaluationArgument]>
Optional argument to pass to [`param: expression`].
### option: Locator.evaluateHandle.timeout
* since: v1.14
* langs: python, java, csharp
- `timeout` <[float]>
Maximum time in milliseconds to wait for the locator before evaluating. Note that after locator is resolved, evaluation itself is not limited by the timeout. Defaults to `30000` (30 seconds). Pass `0` to disable timeout.
### option: Locator.evaluateHandle.timeout
* since: v1.14
* langs: js
- `timeout` <[float]>
Maximum time in milliseconds to wait for the locator before evaluating. Note that after locator is resolved, evaluation itself is not limited by the timeout. Defaults to `0` - no timeout.
## async method: Locator.fill
* since: v1.14
Set a value to the input field.
**Usage**
```js
await page.getByRole('textbox').fill('example value');
```
```java
page.getByRole(AriaRole.TEXTBOX).fill("example value");
```
```python async
await page.get_by_role("textbox").fill("example value")
```
```python sync
page.get_by_role("textbox").fill("example value")
```
```csharp
await page.GetByRole(AriaRole.Textbox).FillAsync("example value");
```
**Details**
This method waits for [actionability](../actionability.md) checks, focuses the element, fills it and triggers an `input` event after filling. Note that you can pass an empty string to clear the input field.
If the target element is not an `<input>`, `<textarea>` or `[contenteditable]` element, this method throws an error. However, if the element is inside the `<label>` element that has an associated [control](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control), the control will be filled instead.
To send fine-grained keyboard events, use [`method: Locator.pressSequentially`].
### param: Locator.fill.value
* since: v1.14
- `value` <[string]>
Value to set for the `<input>`, `<textarea>` or `[contenteditable]` element.
### option: Locator.fill.force = %%-input-force-%%
* since: v1.14
### option: Locator.fill.noWaitAfter = %%-input-no-wait-after-removed-%%
* since: v1.14
### option: Locator.fill.timeout = %%-input-timeout-%%
* since: v1.14
### option: Locator.fill.timeout = %%-input-timeout-js-%%
* since: v1.14
## method: Locator.filter
* since: v1.22
- returns: <[Locator]>
This method narrows existing locator according to the options, for example filters by text.
It can be chained to filter multiple times.
**Usage**
```js
const rowLocator = page.locator('tr');
// ...
await rowLocator
.filter({ hasText: 'text in column 1' })
.filter({ has: page.getByRole('button', { name: 'column 2 button' }) })
.screenshot();
```
```java
Locator rowLocator = page.locator("tr");
// ...
rowLocator
.filter(new Locator.FilterOptions().setHasText("text in column 1"))
.filter(new Locator.FilterOptions().setHas(
page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName("column 2 button"))
))
.screenshot();
```
```python async
row_locator = page.locator("tr")
# ...
await row_locator.filter(has_text="text in column 1").filter(
has=page.get_by_role("button", name="column 2 button")
).screenshot()
```
```python sync
row_locator = page.locator("tr")
# ...
row_locator.filter(has_text="text in column 1").filter(
has=page.get_by_role("button", name="column 2 button")
).screenshot()
```
```csharp
var rowLocator = page.Locator("tr");
// ...
await rowLocator
.Filter(new() { HasText = "text in column 1" })
.Filter(new() {
Has = page.GetByRole(AriaRole.Button, new() { Name = "column 2 button" } )
})
.ScreenshotAsync();
```
### option: Locator.filter.-inline- = %%-locator-options-list-v1.14-%%
* since: v1.22
### option: Locator.filter.hasNot = %%-locator-option-has-not-%%
* since: v1.33
### option: Locator.filter.hasNotText = %%-locator-option-has-not-text-%%
* since: v1.33
### option: Locator.filter.visible = %%-locator-option-visible-%%
* since: v1.51
## method: Locator.first
* since: v1.14
- returns: <[Locator]>
Returns locator to the first matching element.
## async method: Locator.focus
* since: v1.14
Calls [focus](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus) on the matching element.
### option: Locator.focus.timeout = %%-input-timeout-%%
* since: v1.14
### option: Locator.focus.timeout = %%-input-timeout-js-%%
* since: v1.14
## method: Locator.frameLocator
* since: v1.17
- returns: <[FrameLocator]>
When working with iframes, you can create a frame locator that will enter the iframe and allow locating elements
in that iframe:
**Usage**
```js
const locator = page.frameLocator('iframe').getByText('Submit');
await locator.click();
```
```java
Locator locator = page.frameLocator("iframe").getByText("Submit");
locator.click();
```
```python async
locator = page.frame_locator("iframe").get_by_text("Submit")
await locator.click()
```
```python sync
locator = page.frame_locator("iframe").get_by_text("Submit")
locator.click()
```
```csharp
var locator = page.FrameLocator("iframe").GetByText("Submit");
await locator.ClickAsync();
```
### param: Locator.frameLocator.selector = %%-find-selector-%%
* since: v1.17
## async method: Locator.getAttribute
* since: v1.14
- returns: <[null]|[string]>
Returns the matching element's attribute value.
:::warning[Asserting attributes]
If you need to assert an element's attribute, prefer [`method: LocatorAssertions.toHaveAttribute`] to avoid flakiness. See [assertions guide](../test-assertions.md) for more details.
:::
### param: Locator.getAttribute.name
* since: v1.14
- `name` <[string]>
Attribute name to get the value for.
### option: Locator.getAttribute.timeout = %%-input-timeout-%%
* since: v1.14
### option: Locator.getAttribute.timeout = %%-input-timeout-js-%%
* since: v1.14
## method: Locator.getByAltText
* since: v1.27
- returns: <[Locator]>
%%-template-locator-get-by-alt-text-%%
### param: Locator.getByAltText.text = %%-locator-get-by-text-text-%%
### option: Locator.getByAltText.exact = %%-locator-get-by-text-exact-%%
## method: Locator.getByLabel
* since: v1.27
- returns: <[Locator]>
%%-template-locator-get-by-label-text-%%
### param: Locator.getByLabel.text = %%-locator-get-by-text-text-%%
### option: Locator.getByLabel.exact = %%-locator-get-by-text-exact-%%
## method: Locator.getByPlaceholder
* since: v1.27
- returns: <[Locator]>
%%-template-locator-get-by-placeholder-text-%%
### param: Locator.getByPlaceholder.text = %%-locator-get-by-text-text-%%
### option: Locator.getByPlaceholder.exact = %%-locator-get-by-text-exact-%%
## method: Locator.getByRole
* since: v1.27
- returns: <[Locator]>
%%-template-locator-get-by-role-%%
### param: Locator.getByRole.role = %%-get-by-role-to-have-role-role-%%
* since: v1.27
### option: Locator.getByRole.-inline- = %%-locator-get-by-role-option-list-v1.27-%%
* since: v1.27
### option: Locator.getByRole.exact = %%-locator-get-by-role-option-exact-%%
## method: Locator.getByTestId
* since: v1.27
- returns: <[Locator]>
%%-template-locator-get-by-test-id-%%
### param: Locator.getByTestId.testId = %%-locator-get-by-test-id-test-id-%%
* since: v1.27
## method: Locator.getByText
* since: v1.27
- returns: <[Locator]>
%%-template-locator-get-by-text-%%
### param: Locator.getByText.text = %%-locator-get-by-text-text-%%
### option: Locator.getByText.exact = %%-locator-get-by-text-exact-%%
## method: Locator.getByTitle
* since: v1.27
- returns: <[Locator]>
%%-template-locator-get-by-title-%%
### param: Locator.getByTitle.text = %%-locator-get-by-text-text-%%
### option: Locator.getByTitle.exact = %%-locator-get-by-text-exact-%%
## async method: Locator.highlight
* since: v1.20
Highlight the corresponding element(s) on the screen. Useful for debugging, don't commit the code that uses [`method: Locator.highlight`].
## async method: Locator.hover
* since: v1.14
Hover over the matching element.
**Usage**
```js
await page.getByRole('link').hover();
```
```python async
await page.get_by_role("link").hover()
```
```python sync
page.get_by_role("link").hover()
```
```java
page.getByRole(AriaRole.LINK).hover();
```
```csharp
await page.GetByRole(AriaRole.Link).HoverAsync();
```
**Details**
This method hovers over the element by performing the following steps:
1. Wait for [actionability](../actionability.md) checks on the element, unless [`option: force`] option is set.
1. Scroll the element into view if needed.
1. Use [`property: Page.mouse`] to hover over the center of the element, or the specified [`option: position`].
If the element is detached from the DOM at any moment during the action, this method throws.
When all steps combined have not finished during the specified [`option: timeout`], this method throws a
[TimeoutError]. Passing zero timeout disables this.
### option: Locator.hover.position = %%-input-position-%%
* since: v1.14
### option: Locator.hover.modifiers = %%-input-modifiers-%%
* since: v1.14
### option: Locator.hover.force = %%-input-force-%%
* since: v1.14
### option: Locator.hover.timeout = %%-input-timeout-%%
* since: v1.14
### option: Locator.hover.timeout = %%-input-timeout-js-%%
* since: v1.14
### option: Locator.hover.trial = %%-input-trial-with-modifiers-%%
* since: v1.14
### option: Locator.hover.noWaitAfter = %%-input-no-wait-after-removed-%%
* since: v1.28
## async method: Locator.innerHTML
* since: v1.14
- returns: <[string]>
Returns the [`element.innerHTML`](https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML).
### option: Locator.innerHTML.timeout = %%-input-timeout-%%
* since: v1.14
### option: Locator.innerHTML.timeout = %%-input-timeout-js-%%
* since: v1.14
## async method: Locator.innerText
* since: v1.14
- returns: <[string]>
Returns the [`element.innerText`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/innerText).
:::warning[Asserting text]
If you need to assert text on the page, prefer [`method: LocatorAssertions.toHaveText`] with [`option: LocatorAssertions.toHaveText.useInnerText`] option to avoid flakiness. See [assertions guide](../test-assertions.md) for more details.
:::
### option: Locator.innerText.timeout = %%-input-timeout-%%
* since: v1.14
### option: Locator.innerText.timeout = %%-input-timeout-js-%%
* since: v1.14
## async method: Locator.inputValue
* since: v1.14
- returns: <[string]>
Returns the value for the matching `<input>` or `<textarea>` or `<select>` element.
:::warning[Asserting value]
If you need to assert input value, prefer [`method: LocatorAssertions.toHaveValue`] to avoid flakiness. See [assertions guide](../test-assertions.md) for more details.
:::
**Usage**
```js
const value = await page.getByRole('textbox').inputValue();
```
```python async
value = await page.get_by_role("textbox").input_value()
```
```python sync
value = page.get_by_role("textbox").input_value()
```
```java
String value = page.getByRole(AriaRole.TEXTBOX).inputValue();
```
```csharp
String value = await page.GetByRole(AriaRole.Textbox).InputValueAsync();
```
**Details**
Throws elements that are not an input, textarea or a select. However, if the element is inside the `<label>` element that has an associated [control](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control), returns the value of the control.
### option: Locator.inputValue.timeout = %%-input-timeout-%%
* since: v1.14
### option: Locator.inputValue.timeout = %%-input-timeout-js-%%
* since: v1.14
## async method: Locator.isChecked
* since: v1.14
- returns: <[boolean]>
Returns whether the element is checked. Throws if the element is not a checkbox or radio input.
:::warning[Asserting checked state]
If you need to assert that checkbox is checked, prefer [`method: LocatorAssertions.toBeChecked`] to avoid flakiness. See [assertions guide](../test-assertions.md) for more details.
:::
**Usage**
```js
const checked = await page.getByRole('checkbox').isChecked();
```
```java
boolean checked = page.getByRole(AriaRole.CHECKBOX).isChecked();
```
```python async
checked = await page.get_by_role("checkbox").is_checked()
```
```python sync
checked = page.get_by_role("checkbox").is_checked()
```
```csharp
var isChecked = await page.GetByRole(AriaRole.Checkbox).IsCheckedAsync();
```
### option: Locator.isChecked.timeout = %%-input-timeout-%%
* since: v1.14
### option: Locator.isChecked.timeout = %%-input-timeout-js-%%
* since: v1.14
## async method: Locator.isDisabled
* since: v1.14
- returns: <[boolean]>
Returns whether the element is disabled, the opposite of [enabled](../actionability.md#enabled).
:::warning[Asserting disabled state]
If you need to assert that an element is disabled, prefer [`method: LocatorAssertions.toBeDisabled`] to avoid flakiness. See [assertions guide](../test-assertions.md) for more details.
:::
**Usage**
```js
const disabled = await page.getByRole('button').isDisabled();
```
```java
boolean disabled = page.getByRole(AriaRole.BUTTON).isDisabled();
```
```python async
disabled = await page.get_by_role("button").is_disabled()
```
```python sync
disabled = page.get_by_role("button").is_disabled()
```
```csharp
Boolean disabled = await page.GetByRole(AriaRole.Button).IsDisabledAsync();
```
### option: Locator.isDisabled.timeout = %%-input-timeout-%%
* since: v1.14
### option: Locator.isDisabled.timeout = %%-input-timeout-js-%%
* since: v1.14
## async method: Locator.isEditable
* since: v1.14
- returns: <[boolean]>
Returns whether the element is [editable](../actionability.md#editable). If the target element is not an `<input>`, `<textarea>`, `<select>`, `[contenteditable]` and does not have a role allowing `[aria-readonly]`, this method throws an error.
:::warning[Asserting editable state]
If you need to assert that an element is editable, prefer [`method: LocatorAssertions.toBeEditable`] to avoid flakiness. See [assertions guide](../test-assertions.md) for more details.
:::
**Usage**
```js
const editable = await page.getByRole('textbox').isEditable();
```
```java
boolean editable = page.getByRole(AriaRole.TEXTBOX).isEditable();
```
```python async
editable = await page.get_by_role("textbox").is_editable()
```
```python sync
editable = page.get_by_role("textbox").is_editable()
```
```csharp
Boolean editable = await page.GetByRole(AriaRole.Textbox).IsEditableAsync();
```
### option: Locator.isEditable.timeout = %%-input-timeout-%%
* since: v1.14
### option: Locator.isEditable.timeout = %%-input-timeout-js-%%
* since: v1.14
## async method: Locator.isEnabled
* since: v1.14
- returns: <[boolean]>
Returns whether the element is [enabled](../actionability.md#enabled).
:::warning[Asserting enabled state]
If you need to assert that an element is enabled, prefer [`method: LocatorAssertions.toBeEnabled`] to avoid flakiness. See [assertions guide](../test-assertions.md) for more details.
:::
**Usage**
```js
const enabled = await page.getByRole('button').isEnabled();
```
```java
boolean enabled = page.getByRole(AriaRole.BUTTON).isEnabled();
```
```python async
enabled = await page.get_by_role("button").is_enabled()
```
```python sync
enabled = page.get_by_role("button").is_enabled()
```
```csharp
Boolean enabled = await page.GetByRole(AriaRole.Button).IsEnabledAsync();
```
### option: Locator.isEnabled.timeout = %%-input-timeout-%%
* since: v1.14
### option: Locator.isEnabled.timeout = %%-input-timeout-js-%%
* since: v1.14
## async method: Locator.isHidden
* since: v1.14
- returns: <[boolean]>
Returns whether the element is hidden, the opposite of [visible](../actionability.md#visible).
:::warning[Asserting visibility]
If you need to assert that element is hidden, prefer [`method: LocatorAssertions.toBeHidden`] to avoid flakiness. See [assertions guide](../test-assertions.md) for more details.
:::
**Usage**
```js
const hidden = await page.getByRole('button').isHidden();
```
```java
boolean hidden = page.getByRole(AriaRole.BUTTON).isHidden();
```
```python async
hidden = await page.get_by_role("button").is_hidden()
```
```python sync
hidden = page.get_by_role("button").is_hidden()
```
```csharp
Boolean hidden = await page.GetByRole(AriaRole.Button).IsHiddenAsync();
```
### option: Locator.isHidden.timeout
* since: v1.14
* deprecated: This option is ignored. [`method: Locator.isHidden`] does not wait for the element to become hidden and returns immediately.
- `timeout` <[float]>
## async method: Locator.isVisible
* since: v1.14
- returns: <[boolean]>
Returns whether the element is [visible](../actionability.md#visible).
:::warning[Asserting visibility]
If you need to assert that element is visible, prefer [`method: LocatorAssertions.toBeVisible`] to avoid flakiness. See [assertions guide](../test-assertions.md) for more details.
:::
**Usage**
```js
const visible = await page.getByRole('button').isVisible();
```
```java
boolean visible = page.getByRole(AriaRole.BUTTON).isVisible();
```
```python async
visible = await page.get_by_role("button").is_visible()
```
```python sync
visible = page.get_by_role("button").is_visible()
```
```csharp
Boolean visible = await page.GetByRole(AriaRole.Button).IsVisibleAsync();
```
### option: Locator.isVisible.timeout
* since: v1.14
* deprecated: This option is ignored. [`method: Locator.isVisible`] does not wait for the element to become visible and returns immediately.
- `timeout` <[float]>
## method: Locator.last
* since: v1.14
- returns: <[Locator]>
Returns locator to the last matching element.
**Usage**
```js
const banana = await page.getByRole('listitem').last();
```
```python async
banana = await page.get_by_role("listitem").last
```
```python sync
banana = page.get_by_role("listitem").last
```
```java
Locator banana = page.getByRole(AriaRole.LISTITEM).last();
```
```csharp
var banana = await page.GetByRole(AriaRole.Listitem).Last(1);
```
## method: Locator.locator
* since: v1.14
- returns: <[Locator]>
%%-template-locator-locator-%%
### param: Locator.locator.selectorOrLocator = %%-find-selector-or-locator-%%
* since: v1.14
### option: Locator.locator.-inline- = %%-locator-options-list-v1.14-%%
* since: v1.14
### option: Locator.locator.hasNot = %%-locator-option-has-not-%%
* since: v1.33
### option: Locator.locator.hasNotText = %%-locator-option-has-not-text-%%
* since: v1.33
## method: Locator.nth
* since: v1.14
- returns: <[Locator]>
Returns locator to the n-th matching element. It's zero based, `nth(0)` selects the first element.
**Usage**
```js
const banana = await page.getByRole('listitem').nth(2);
```
```python async
banana = await page.get_by_role("listitem").nth(2)
```
```python sync
banana = page.get_by_role("listitem").nth(2)
```
```java
Locator banana = page.getByRole(AriaRole.LISTITEM).nth(2);
```
```csharp
var banana = await page.GetByRole(AriaRole.Listitem).Nth(2);
```
### param: Locator.nth.index
* since: v1.14
- `index` <[int]>
## method: Locator.or
* since: v1.33
* langs:
- alias-python: or_
- returns: <[Locator]>
Creates a locator matching all elements that match one or both of the two locators.
Note that when both locators match something, the resulting locator will have multiple matches, potentially causing a [locator strictness](../locators.md#strictness) violation.
**Usage**
Consider a scenario where you'd like to click on a "New email" button, but sometimes a security settings dialog shows up instead. In this case, you can wait for either a "New email" button, or a dialog and act accordingly.
:::note
If both "New email" button and security dialog appear on screen, the "or" locator will match both of them,
possibly throwing the ["strict mode violation" error](../locators.md#strictness). In this case, you can use [`method: Locator.first`] to only match one of them.
:::
```js
const newEmail = page.getByRole('button', { name: 'New' });
const dialog = page.getByText('Confirm security settings');
await expect(newEmail.or(dialog).first()).toBeVisible();
if (await dialog.isVisible())
await page.getByRole('button', { name: 'Dismiss' }).click();
await newEmail.click();
```
```java
Locator newEmail = page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName("New"));
Locator dialog = page.getByText("Confirm security settings");
assertThat(newEmail.or(dialog).first()).isVisible();
if (dialog.isVisible())
page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName("Dismiss")).click();
newEmail.click();
```
```python async
new_email = page.get_by_role("button", name="New")
dialog = page.get_by_text("Confirm security settings")
await expect(new_email.or_(dialog).first).to_be_visible()
if (await dialog.is_visible()):
await page.get_by_role("button", name="Dismiss").click()
await new_email.click()
```
```python sync
new_email = page.get_by_role("button", name="New")
dialog = page.get_by_text("Confirm security settings")
expect(new_email.or_(dialog).first).to_be_visible()
if (dialog.is_visible()):
page.get_by_role("button", name="Dismiss").click()
new_email.click()
```
```csharp
var newEmail = page.GetByRole(AriaRole.Button, new() { Name = "New" });
var dialog = page.GetByText("Confirm security settings");
await Expect(newEmail.Or(dialog).First).ToBeVisibleAsync();
if (await dialog.IsVisibleAsync())
await page.GetByRole(AriaRole.Button, new() { Name = "Dismiss" }).ClickAsync();
await newEmail.ClickAsync();
```
### param: Locator.or.locator
* since: v1.33
- `locator` <[Locator]>
Alternative locator to match.
## method: Locator.page
* since: v1.19
- returns: <[Page]>
A page this locator belongs to.
## async method: Locator.press
* since: v1.14
Focuses the matching element and presses a combination of the keys.
**Usage**
```js
await page.getByRole('textbox').press('Backspace');
```
```java
page.getByRole(AriaRole.TEXTBOX).press("Backspace");
```
```python async
await page.get_by_role("textbox").press("Backspace")
```
```python sync
page.get_by_role("textbox").press("Backspace")
```
```csharp
await page.GetByRole(AriaRole.Textbox).PressAsync("Backspace");
```
**Details**
Focuses the element, and then uses [`method: Keyboard.down`] and [`method: Keyboard.up`].
[`param: key`] can specify the intended
[keyboardEvent.key](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key) value or a single character to
generate the text for. A superset of the [`param: key`] values can be found
[here](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values). Examples of the keys are:
`F1` - `F12`, `Digit0`- `Digit9`, `KeyA`- `KeyZ`, `Backquote`, `Minus`, `Equal`, `Backslash`, `Backspace`, `Tab`,
`Delete`, `Escape`, `ArrowDown`, `End`, `Enter`, `Home`, `Insert`, `PageDown`, `PageUp`, `ArrowRight`, `ArrowUp`, etc.
Following modification shortcuts are also supported: `Shift`, `Control`, `Alt`, `Meta`, `ShiftLeft`, `ControlOrMeta`.
`ControlOrMeta` resolves to `Control` on Windows and Linux and to `Meta` on macOS.
Holding down `Shift` will type the text that corresponds to the [`param: key`] in the upper case.
If [`param: key`] is a single character, it is case-sensitive, so the values `a` and `A` will generate different
respective texts.
Shortcuts such as `key: "Control+o"`, `key: "Control++` or `key: "Control+Shift+T"` are supported as well. When specified with the
modifier, modifier is pressed and being held while the subsequent key is being pressed.
### param: Locator.press.key
* since: v1.14
- `key` <[string]>
Name of the key to press or a character to generate, such as `ArrowLeft` or `a`.
### option: Locator.press.delay
* since: v1.14
- `delay` <[float]>
Time to wait between `keydown` and `keyup` in milliseconds. Defaults to 0.
### option: Locator.press.noWaitAfter = %%-input-no-wait-after-%%
* since: v1.14
### option: Locator.press.timeout = %%-input-timeout-%%
* since: v1.14
### option: Locator.press.timeout = %%-input-timeout-js-%%
* since: v1.14
## async method: Locator.pressSequentially
* since: v1.38
:::tip
In most cases, you should use [`method: Locator.fill`] instead. You only need to press keys one by one if there is special keyboard handling on the page.
:::
Focuses the element, and then sends a `keydown`, `keypress`/`input`, and `keyup` event for each character in the text.
To press a special key, like `Control` or `ArrowDown`, use [`method: Locator.press`].
**Usage**
```js
await locator.pressSequentially('Hello'); // Types instantly
await locator.pressSequentially('World', { delay: 100 }); // Types slower, like a user
```
```java
locator.pressSequentially("Hello"); // Types instantly
locator.pressSequentially("World", new Locator.pressSequentiallyOptions().setDelay(100)); // Types slower, like a user
```
```python async
await locator.press_sequentially("hello") # types instantly
await locator.press_sequentially("world", delay=100) # types slower, like a user
```
```python sync
locator.press_sequentially("hello") # types instantly
locator.press_sequentially("world", delay=100) # types slower, like a user
```
```csharp
await locator.PressSequentiallyAsync("Hello"); // Types instantly
await locator.PressSequentiallyAsync("World", new() { Delay = 100 }); // Types slower, like a user
```
An example of typing into a text field and then submitting the form:
```js
const locator = page.getByLabel('Password');
await locator.pressSequentially('my password');
await locator.press('Enter');
```
```java
Locator locator = page.getByLabel("Password");
locator.pressSequentially("my password");
locator.press("Enter");
```
```python async
locator = page.get_by_label("Password")
await locator.press_sequentially("my password")
await locator.press("Enter")
```
```python sync
locator = page.get_by_label("Password")
locator.press_sequentially("my password")
locator.press("Enter")
```
```csharp
var locator = page.GetByLabel("Password");
await locator.PressSequentiallyAsync("my password");
await locator.PressAsync("Enter");
```
### param: Locator.pressSequentially.text
* since: v1.38
- `text` <[string]>
String of characters to sequentially press into a focused element.
### option: Locator.pressSequentially.delay
* since: v1.38
- `delay` <[float]>
Time to wait between key presses in milliseconds. Defaults to 0.
### option: Locator.pressSequentially.noWaitAfter = %%-input-no-wait-after-removed-%%
* since: v1.38
### option: Locator.pressSequentially.timeout = %%-input-timeout-%%
* since: v1.38
### option: Locator.pressSequentially.timeout = %%-input-timeout-js-%%
* since: v1.38
## async method: Locator.screenshot
* since: v1.14
- returns: <[Buffer]>
Take a screenshot of the element matching the locator.
**Usage**
```js
await page.getByRole('link').screenshot();
```
```java
page.getByRole(AriaRole.LINK).screenshot();
```
```python async
await page.get_by_role("link").screenshot()
```
```python sync
page.get_by_role("link").screenshot()
```
```csharp
await page.GetByRole(AriaRole.Link).ScreenshotAsync();
```
Disable animations and save screenshot to a file:
```js
await page.getByRole('link').screenshot({ animations: 'disabled', path: 'link.png' });
```
```java
page.getByRole(AriaRole.LINK).screenshot(new Locator.ScreenshotOptions()
.setAnimations(ScreenshotAnimations.DISABLED)
.setPath(Paths.get("example.png")));
```
```python async
await page.get_by_role("link").screenshot(animations="disabled", path="link.png")
```
```python sync
page.get_by_role("link").screenshot(animations="disabled", path="link.png")
```
```csharp
await page.GetByRole(AriaRole.Link).ScreenshotAsync(new() {
Animations = ScreenshotAnimations.Disabled,
Path = "link.png"
});
```
**Details**
This method captures a screenshot of the page, clipped to the size and position of a particular element matching the locator. If the element is covered by other elements, it will not be actually visible on the screenshot. If the element is a scrollable container, only the currently scrolled content will be visible on the screenshot.
This method waits for the [actionability](../actionability.md) checks, then scrolls element into view before taking a
screenshot. If the element is detached from DOM, the method throws an error.
Returns the buffer with the captured screenshot.
### option: Locator.screenshot.-inline- = %%-screenshot-options-common-list-v1.8-%%
* since: v1.14
### option: Locator.screenshot.timeout = %%-input-timeout-%%
* since: v1.14
### option: Locator.screenshot.timeout = %%-input-timeout-js-%%
* since: v1.14
### option: Locator.screenshot.maskColor = %%-screenshot-option-mask-color-%%
* since: v1.34
### option: Locator.screenshot.style = %%-screenshot-option-style-%%
* since: v1.41
## async method: Locator.scrollIntoViewIfNeeded
* since: v1.14
This method waits for [actionability](../actionability.md) checks, then tries to scroll element into view, unless it is
completely visible as defined by
[IntersectionObserver](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API)'s `ratio`.
See [scrolling](../input.md#scrolling) for alternative ways to scroll.
### option: Locator.scrollIntoViewIfNeeded.timeout = %%-input-timeout-%%
* since: v1.14
### option: Locator.scrollIntoViewIfNeeded.timeout = %%-input-timeout-js-%%
* since: v1.14
## async method: Locator.selectOption
* since: v1.14
- returns: <[Array]<[string]>>
Selects option or options in `<select>`.
**Details**
This method waits for [actionability](../actionability.md) checks, waits until all specified options are present in the `<select>` element and selects these options.
If the target element is not a `<select>` element, this method throws an error. However, if the element is inside the `<label>` element that has an associated [control](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control), the control will be used instead.
Returns the array of option values that have been successfully selected.
Triggers a `change` and `input` event once all the provided options have been selected.
**Usage**
```html
<select multiple>
<option value="red">Red</option>
<option value="green">Green</option>
<option value="blue">Blue</option>
</select>
```
```js
// single selection matching the value or label
element.selectOption('blue');
// single selection matching the label
element.selectOption({ label: 'Blue' });
// multiple selection for red, green and blue options
element.selectOption(['red', 'green', 'blue']);
```
```java
// single selection matching the value or label
element.selectOption("blue");
// single selection matching the label
element.selectOption(new SelectOption().setLabel("Blue"));
// multiple selection for blue, red and second option
element.selectOption(new String[] {"red", "green", "blue"});
```
```python async
# single selection matching the value or label
await element.select_option("blue")
# single selection matching the label
await element.select_option(label="blue")
# multiple selection for blue, red and second option
await element.select_option(value=["red", "green", "blue"])
```
```python sync
# single selection matching the value or label
element.select_option("blue")
# single selection matching the label
element.select_option(label="blue")
# multiple selection for blue, red and second option
element.select_option(value=["red", "green", "blue"])
```
```csharp
// single selection matching the value or label
await element.SelectOptionAsync(new[] { "blue" });
// single selection matching the label
await element.SelectOptionAsync(new[] { new SelectOptionValue() { Label = "blue" } });
// multiple selection for blue, red and second option
await element.SelectOptionAsync(new[] { "red", "green", "blue" });
```
### param: Locator.selectOption.values = %%-select-options-values-%%
* since: v1.14
### option: Locator.selectOption.force = %%-input-force-%%
* since: v1.14
### option: Locator.selectOption.noWaitAfter = %%-input-no-wait-after-removed-%%
* since: v1.14
### option: Locator.selectOption.timeout = %%-input-timeout-%%
* since: v1.14
### option: Locator.selectOption.timeout = %%-input-timeout-js-%%
* since: v1.14
### param: Locator.selectOption.element = %%-python-select-options-element-%%
* since: v1.14
### param: Locator.selectOption.index = %%-python-select-options-index-%%
* since: v1.14
### param: Locator.selectOption.value = %%-python-select-options-value-%%
* since: v1.14
### param: Locator.selectOption.label = %%-python-select-options-label-%%
* since: v1.14
## async method: Locator.selectText
* since: v1.14
This method waits for [actionability](../actionability.md) checks, then focuses the element and selects all its text
content.
If the element is inside the `<label>` element that has an associated [control](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control), focuses and selects text in the control instead.
### option: Locator.selectText.force = %%-input-force-%%
* since: v1.14
### option: Locator.selectText.timeout = %%-input-timeout-%%
* since: v1.14
### option: Locator.selectText.timeout = %%-input-timeout-js-%%
* since: v1.14
## async method: Locator.setChecked
* since: v1.15
Set the state of a checkbox or a radio element.
**Usage**
```js
await page.getByRole('checkbox').setChecked(true);
```
```java
page.getByRole(AriaRole.CHECKBOX).setChecked(true);
```
```python async
await page.get_by_role("checkbox").set_checked(True)
```
```python sync
page.get_by_role("checkbox").set_checked(True)
```
```csharp
await page.GetByRole(AriaRole.Checkbox).SetCheckedAsync(true);
```
**Details**
This method checks or unchecks an element by performing the following steps:
1. Ensure that matched element is a checkbox or a radio input. If not, this method throws.
1. If the element already has the right checked state, this method returns immediately.
1. Wait for [actionability](../actionability.md) checks on the matched element, unless [`option: force`] option is
set. If the element is detached during the checks, the whole action is retried.
1. Scroll the element into view if needed.
1. Use [`property: Page.mouse`] to click in the center of the element.
1. Ensure that the element is now checked or unchecked. If not, this method throws.
When all steps combined have not finished during the specified [`option: timeout`], this method throws a
[TimeoutError]. Passing zero timeout disables this.
### param: Locator.setChecked.checked = %%-input-checked-%%
* since: v1.15
### option: Locator.setChecked.force = %%-input-force-%%
* since: v1.15
### option: Locator.setChecked.noWaitAfter = %%-input-no-wait-after-removed-%%
* since: v1.15
### option: Locator.setChecked.position = %%-input-position-%%
* since: v1.15
### option: Locator.setChecked.timeout = %%-input-timeout-%%
* since: v1.15
### option: Locator.setChecked.timeout = %%-input-timeout-js-%%
* since: v1.15
### option: Locator.setChecked.trial = %%-input-trial-%%
* since: v1.15
## async method: Locator.setInputFiles
* since: v1.14
Upload file or multiple files into `<input type=file>`.
For inputs with a `[webkitdirectory]` attribute, only a single directory path is supported.
**Usage**
```js
// Select one file
await page.getByLabel('Upload file').setInputFiles(path.join(__dirname, 'myfile.pdf'));
// Select multiple files
await page.getByLabel('Upload files').setInputFiles([
path.join(__dirname, 'file1.txt'),
path.join(__dirname, 'file2.txt'),
]);
// Select a directory
await page.getByLabel('Upload directory').setInputFiles(path.join(__dirname, 'mydir'));
// Remove all the selected files
await page.getByLabel('Upload file').setInputFiles([]);
// Upload buffer from memory
await page.getByLabel('Upload file').setInputFiles({
name: 'file.txt',
mimeType: 'text/plain',
buffer: Buffer.from('this is test')
});
```
```java
// Select one file
page.getByLabel("Upload file").setInputFiles(Paths.get("myfile.pdf"));
// Select multiple files
page.getByLabel("Upload files").setInputFiles(new Path[] {Paths.get("file1.txt"), Paths.get("file2.txt")});
// Select a directory
page.getByLabel("Upload directory").setInputFiles(Paths.get("mydir"));
// Remove all the selected files
page.getByLabel("Upload file").setInputFiles(new Path[0]);
// Upload buffer from memory
page.getByLabel("Upload file").setInputFiles(new FilePayload(
"file.txt", "text/plain", "this is test".getBytes(StandardCharsets.UTF_8)));
```
```python async
# Select one file
await page.get_by_label("Upload file").set_input_files('myfile.pdf')
# Select multiple files
await page.get_by_label("Upload files").set_input_files(['file1.txt', 'file2.txt'])
# Select a directory
await page.get_by_label("Upload directory").set_input_files('mydir')
# Remove all the selected files
await page.get_by_label("Upload file").set_input_files([])
# Upload buffer from memory
await page.get_by_label("Upload file").set_input_files(
files=[
{"name": "test.txt", "mimeType": "text/plain", "buffer": b"this is a test"}
],
)
```
```python sync
# Select one file
page.get_by_label("Upload file").set_input_files('myfile.pdf')
# Select multiple files
page.get_by_label("Upload files").set_input_files(['file1.txt', 'file2.txt'])
# Select a directory
page.get_by_label("Upload directory").set_input_files('mydir')
# Remove all the selected files
page.get_by_label("Upload file").set_input_files([])
# Upload buffer from memory
page.get_by_label("Upload file").set_input_files(
files=[
{"name": "test.txt", "mimeType": "text/plain", "buffer": b"this is a test"}
],
)
```
```csharp
// Select one file
await page.GetByLabel("Upload file").SetInputFilesAsync("myfile.pdf");
// Select multiple files
await page.GetByLabel("Upload files").SetInputFilesAsync(new[] { "file1.txt", "file12.txt" });
// Select a directory
await page.GetByLabel("Upload directory").SetInputFilesAsync("mydir");
// Remove all the selected files
await page.GetByLabel("Upload file").SetInputFilesAsync(new[] {});
// Upload buffer from memory
await page.GetByLabel("Upload file").SetInputFilesAsync(new FilePayload
{
Name = "file.txt",
MimeType = "text/plain",
Buffer = System.Text.Encoding.UTF8.GetBytes("this is a test"),
});
```
**Details**
Sets the value of the file input to these file paths or files. If some of the `filePaths` are relative paths, then they
are resolved relative to the current working directory. For empty array, clears the selected files.
This method expects [Locator] to point to an
[input element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input). However, if the element is inside the `<label>` element that has an associated [control](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control), targets the control instead.
### param: Locator.setInputFiles.files = %%-input-files-%%
* since: v1.14
### option: Locator.setInputFiles.noWaitAfter = %%-input-no-wait-after-removed-%%
* since: v1.14
### option: Locator.setInputFiles.timeout = %%-input-timeout-%%
* since: v1.14
### option: Locator.setInputFiles.timeout = %%-input-timeout-js-%%
* since: v1.14
## async method: Locator.tap
* since: v1.14
Perform a tap gesture on the element matching the locator. For examples of emulating other gestures by manually dispatching touch events, see the [emulating legacy touch events](../touch-events.md) page.
**Details**
This method taps the element by performing the following steps:
1. Wait for [actionability](../actionability.md) checks on the element, unless [`option: force`] option is set.
1. Scroll the element into view if needed.
1. Use [`property: Page.touchscreen`] to tap the center of the element, or the specified [`option: position`].
If the element is detached from the DOM at any moment during the action, this method throws.
When all steps combined have not finished during the specified [`option: timeout`], this method throws a
[TimeoutError]. Passing zero timeout disables this.
:::note
`element.tap()` requires that the `hasTouch` option of the browser context be set to true.
:::
### option: Locator.tap.position = %%-input-position-%%
* since: v1.14
### option: Locator.tap.modifiers = %%-input-modifiers-%%
* since: v1.14
### option: Locator.tap.force = %%-input-force-%%
* since: v1.14
### option: Locator.tap.noWaitAfter = %%-input-no-wait-after-removed-%%
* since: v1.14
### option: Locator.tap.timeout = %%-input-timeout-%%
* since: v1.14
### option: Locator.tap.timeout = %%-input-timeout-js-%%
* since: v1.14
### option: Locator.tap.trial = %%-input-trial-with-modifiers-%%
* since: v1.14
## async method: Locator.textContent
* since: v1.14
- returns: <[null]|[string]>
Returns the [`node.textContent`](https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent).
:::warning[Asserting text]
If you need to assert text on the page, prefer [`method: LocatorAssertions.toHaveText`] to avoid flakiness. See [assertions guide](../test-assertions.md) for more details.
:::
### option: Locator.textContent.timeout = %%-input-timeout-%%
* since: v1.14
### option: Locator.textContent.timeout = %%-input-timeout-js-%%
* since: v1.14
## method: Locator.toString
* since: v1.57
* langs: js
- returns: <[string]>
Returns a human-readable representation of the locator, using the [`method: Locator.description`] if one exists; otherwise, it generates a string based on the locator's selector.
## async method: Locator.type
* since: v1.14
* deprecated: In most cases, you should use [`method: Locator.fill`] instead. You only need to press keys one by one if there is special keyboard handling on the page - in this case use [`method: Locator.pressSequentially`].
Focuses the element, and then sends a `keydown`, `keypress`/`input`, and `keyup` event for each character in the text.
To press a special key, like `Control` or `ArrowDown`, use [`method: Locator.press`].
**Usage**
### param: Locator.type.text
* since: v1.14
- `text` <[string]>
A text to type into a focused element.
### option: Locator.type.delay
* since: v1.14
- `delay` <[float]>
Time to wait between key presses in milliseconds. Defaults to 0.
### option: Locator.type.noWaitAfter = %%-input-no-wait-after-removed-%%
* since: v1.14
### option: Locator.type.timeout = %%-input-timeout-%%
* since: v1.14
### option: Locator.type.timeout = %%-input-timeout-js-%%
* since: v1.14
## async method: Locator.uncheck
* since: v1.14
Ensure that checkbox or radio element is unchecked.
**Usage**
```js
await page.getByRole('checkbox').uncheck();
```
```java
page.getByRole(AriaRole.CHECKBOX).uncheck();
```
```python async
await page.get_by_role("checkbox").uncheck()
```
```python sync
page.get_by_role("checkbox").uncheck()
```
```csharp
await page.GetByRole(AriaRole.Checkbox).UncheckAsync();
```
**Details**
This method unchecks the element by performing the following steps:
1. Ensure that element is a checkbox or a radio input. If not, this method throws. If the element is already
unchecked, this method returns immediately.
1. Wait for [actionability](../actionability.md) checks on the element, unless [`option: force`] option is set.
1. Scroll the element into view if needed.
1. Use [`property: Page.mouse`] to click in the center of the element.
1. Ensure that the element is now unchecked. If not, this method throws.
If the element is detached from the DOM at any moment during the action, this method throws.
When all steps combined have not finished during the specified [`option: timeout`], this method throws a
[TimeoutError]. Passing zero timeout disables this.
### option: Locator.uncheck.position = %%-input-position-%%
* since: v1.14
### option: Locator.uncheck.force = %%-input-force-%%
* since: v1.14
### option: Locator.uncheck.noWaitAfter = %%-input-no-wait-after-removed-%%
* since: v1.14
### option: Locator.uncheck.timeout = %%-input-timeout-%%
* since: v1.14
### option: Locator.uncheck.timeout = %%-input-timeout-js-%%
* since: v1.14
### option: Locator.uncheck.trial = %%-input-trial-%%
* since: v1.14
## async method: Locator.waitFor
* since: v1.16
Returns when element specified by locator satisfies the [`option: state`] option.
If target element already satisfies the condition, the method returns immediately. Otherwise, waits for up to
[`option: timeout`] milliseconds until the condition is met.
**Usage**
```js
const orderSent = page.locator('#order-sent');
await orderSent.waitFor();
```
```java
Locator orderSent = page.locator("#order-sent");
orderSent.waitFor();
```
```python async
order_sent = page.locator("#order-sent")
await order_sent.wait_for()
```
```python sync
order_sent = page.locator("#order-sent")
order_sent.wait_for()
```
```csharp
var orderSent = page.Locator("#order-sent");
orderSent.WaitForAsync();
```
### option: Locator.waitFor.state = %%-wait-for-selector-state-%%
* since: v1.16
### option: Locator.waitFor.timeout = %%-input-timeout-%%
* since: v1.16
### option: Locator.waitFor.timeout = %%-input-timeout-js-%%
* since: v1.16