Skip to content

Browser

Reference

Source code in milan/browser.py
 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
class Browser:
    TRANSLATE_ERRORS = {}

    @classmethod
    def start(cls, *args, **kwargs):
        return BrowserContext(cls, *args, **kwargs)

    def __init__(
            self,
            animations=True,
            short_selector_retry_interval=0.2,
            short_selector_timeout=1,
            selector_retry_interval=0.2,
            selector_timeout=3,
    ):

        self.animations = animations
        self.short_selector_retry_interval = short_selector_retry_interval
        self.short_selector_timeout = short_selector_timeout
        self.selector_retry_interval = selector_retry_interval
        self.selector_timeout = selector_timeout

        self.id = unique_id()

        self.logger = logging.getLogger(
            f'milan.{self.__class__.__name__.lower()}.{self.id}',
        )

        self._event_router = EventRouter()
        self._error = None

    def __repr__(self):
        return f'<{self.__class__.__name__}(id={self.id})>'

    def _get_sub_logger(self, name):
        return logging.getLogger(f'{self.logger.name}.{name}')

    def _get_animations(self, local_override):
        if local_override is not None:
            return local_override

        return self.animations

    def _get_short_selector_retry_interval(self, local_override):
        if local_override is not None:
            return local_override

        return self.short_selector_retry_interval

    def _get_short_selector_timeout(self, local_override):
        if local_override is not None:
            return local_override

        return self.short_selector_timeout

    def _get_selector_retry_interval(self, local_override):
        if local_override is not None:
            return local_override

        return self.selector_retry_interval

    def _get_selector_timeout(self, local_override):
        if local_override is not None:
            return local_override

        return self.selector_timeout

    # events ##################################################################
    @browser_function
    def await_browser_load(self, timeout=None, await_future=True):
        """
        Waits for the next JavaScript window load event (`window.onload`).

        `timeout` can be a positive number in seconds or `None`. If the is
        `None`, the default timeout is used.

        If `await_future` is true, the method blocks until the next event gets
        fired. If not, a `concurrent.futures.Future` object is returned that
        can be awaited outside the method.
        """

        return self._event_router.await_event(
            name='browser_load',
            timeout=timeout,
            await_future=await_future,
        )

    @browser_function
    def await_browser_navigation(
            self,
            url=None,
            timeout=None,
            await_future=True,
    ):

        """
        Waits for the next navigation event of the browser.

        If `url` is set, the browser waits until the given URL is present.

        `timeout` can be a positive number in seconds or `None`. If the is
        `None`, the default timeout is used.

        If `await_future` is true, the method blocks until the next event gets
        fired. If not, a `concurrent.futures.Future` object is returned that
        can be awaited outside the method.
        """

        if url:
            return self._event_router.await_state(
                name='browser_url',
                value=URL.normalize(url),
                timeout=timeout,
                await_future=await_future,
            )

        return self._event_router.await_event(
            name='browser_navigation',
            timeout=timeout,
            await_future=await_future,
        )

    # frontend methods ########################################################
    @browser_function
    @frontend_function
    def evaluate(self, expression, window=0):
        """
        Evaluates the given JavaScript expression in the given window and
        returns the result.

        If `window` is set to `None`, the expression gets evaluated in the
        Milan frontend.
        """

        # evaluate in the real browser
        if window is None:
            return self._browser_evaluate(
                expression=commands.gen_evaluate_command(
                    expression=expression,
                ),
            )

        # evaluate in one of the windows
        return self._browser_evaluate(
            expression=commands.gen_window_evaluate_command(
                window_index=window,
                expression=expression,
            ),
        )

    @browser_function
    @frontend_function
    def add_style_sheet(self, text, window=0):
        """
        Adds a CSS stylesheet as text to the given window.
        """

        # add to browser
        if window is None:
            return self._browser_evaluate(
                expression=commands.gen_add_style_sheet_command(
                    text=text,
                ),
            )

        # add to window
        return self._browser_evaluate(
            expression=commands.gen_window_add_style_sheet_command(
                window_index=window,
                text=text,
            ),
        )

    # window manager
    @frontend_function
    @browser_function
    def get_size(self):
        """
        Returns the size of browser as dict.

        Example return value: `{'height': 720, 'width': 1_280}`
        """

        return self._browser_evaluate(
            expression=commands.gen_window_manager_get_size_command(),
        )

    @browser_function
    def set_size(self, width=0, height=0, even_values=True):
        """
        Resizes the browser to the given width and height.

        If `even_values` is set to true, odd values get rounded to even
        numbers. This is necessary for some FFmpeg filters.
        """

        if even_values:
            width = width + (width % 2)
            height = height + (height % 2)

        return self._browser_set_size(
            width=width,
            height=height,
        )

    @frontend_function
    @browser_function
    def get_window_count(self):
        """
        Returns the count of visible browser windows as integer.
        """

        return self._browser_evaluate(
            expression=commands.gen_window_manager_get_window_count_command(),
        )

    @frontend_function
    @browser_function
    def split(self):
        """
        Split the frontend clockwise into multiple windows.

        Max splits are three. So you can have four windows tops.
        """

        self.logger.info('splitting window')

        return self._browser_evaluate(
            expression=commands.gen_window_manager_split_command(),
        )

    @frontend_function
    @browser_function
    def set_background_url(self, url):
        """
        Sets the URL of the frontends background IFrame.

        Default is `/_milan/frontend/background/index.html`
        """

        return self._browser_evaluate(
            expression=commands.gen_window_manager_set_background_url_command(
                url=url,
            ),
        )

    @frontend_function
    @browser_function
    def set_watermark(self, text):
        """
        Sets the watermark of the frontends background.

        Default is `f'Milan v{milan.VERSION_STRING}'`
        """

        return self._browser_evaluate(
            expression=commands.gen_window_manager_set_watermark_command(
                text=text,
            ),
        )

    @frontend_function
    @browser_function
    def set_background(self, background):
        """
        Sets the background as CSS property.

        Example values:
          - `red`
          - `#FF0000`
          - `linear-gradient(0deg, rgba(34,193,195,1) 0%, rgba(253,187,45,1) 100%)`
        """

        return self._browser_evaluate(
            expression=commands.gen_window_manager_set_background_command(
                background=background,
            ),
        )

    @frontend_function
    @browser_function
    def force_rerender(self):
        return self._browser_evaluate(
            expression=commands.gen_window_manager_force_rerender_command(),
        )

    # cursor
    @frontend_function
    @browser_function
    def show_cursor(self):
        """
        Shows cursor.

        Has no effect if cursor is already visible.
        """

        self.logger.info('showing cursor')

        return self._browser_evaluate(
            expression=commands.gen_cursor_show_command(),
        )

    @frontend_function
    @browser_function
    def hide_cursor(self):
        """
        Hides cursor.

        Has no effect if cursor is already visible.
        """

        self.logger.info('hiding cursor')

        return self._browser_evaluate(
            expression=commands.gen_cursor_hide_command(),
        )

    @frontend_function
    @browser_function
    def cursor_is_visible(self):
        """
        Returns whether the cursor is visible as bool.
        """

        return self._browser_evaluate(
            expression=commands.gen_cursor_is_visible_command(),
        )

    @frontend_function
    @browser_function
    def move_cursor(
            self,
            x=0,
            y=0,
            animation=None,
    ):

        """
        Moves cursor to given X and Y coordinates.

        If `animation` is set to true, the cursor is animated. If animation is
        set to `None` the `Browser.animation` property is used to determine if
        an animation should be played.
        """

        self.logger.info('moving cursor to x=%s y=%s', x, y)

        return self._browser_evaluate(
            expression=commands.gen_cursor_move_to_command(
                x=float(x),
                y=float(y),
                animation=self._get_animations(animation),
            ),
        )

    @frontend_function
    @browser_function
    def move_cursor_to_home(self, animation=None):
        """
        Moves cursor to the middle of the screen.

        If `animation` is set to true, the cursor is animated. If animation is
        set to `None` the `Browser.animation` property is used to determine if
        an animation should be played.
        """

        self.logger.info('moving cursor to home')

        return self._browser_evaluate(
            expression=commands.gen_cursor_move_to_home_command(
                animation=self._get_animations(animation),
            ),
        )

    @frontend_function
    @browser_function
    def get_cursor_position(self):
        """
        Returns the cursor position as dict.

        Example return value: `{'x': 640, 'y': 360}`
        """

        return self._browser_evaluate(
            expression=commands.gen_cursor_get_position_command(),
        )

    # window
    @frontend_function
    @browser_function
    def reload(self, window=0, animation=None):
        """
        Reloads the given window.

        If `animation` is set to true, an animation is played that uses the
        cursor to click on the reload button of the given window.

        If `animation` is set to `None` the `Browser.animation` property is
        used to determine if an animation should be played.
        """

        self.logger.info('reloading window %s', window)

        return self._browser_evaluate(
            expression=commands.gen_window_reload_command(
                window_index=window,
                animation=self._get_animations(animation),
            ),
        )

    # window
    @frontend_function
    @browser_function
    def navigate_back(self, window=0, animation=None):
        """
        Moves back in the history of the given window.

        If `animation` is set to true, an animation is played that uses the
        cursor to click on the back button of the given window.

        If `animation` is set to `None` the `Browser.animation` property is
        used to determine if an animation should be played.
        """

        self.logger.info('navigating window %s back', window)

        return self._browser_evaluate(
            expression=commands.gen_window_navigate_back_command(
                window_index=window,
                animation=self._get_animations(animation),
            ),
        )

    @frontend_function
    @browser_function
    def navigate_forward(self, window=0, animation=None):
        """
        Moves forward in the history of the given window.

        If `animation` is set to true, an animation is played that uses the
        cursor to click on the forward button of the given window.

        If `animation` is set to `None` the `Browser.animation` property is
        used to determine if an animation should be played.
        """

        self.logger.info('navigating window %s forward', window)

        return self._browser_evaluate(
            expression=commands.gen_window_navigate_forward_command(
                window_index=window,
                animation=self._get_animations(animation),
            ),
        )

    @frontend_function
    @browser_function
    def get_fullscreen(self, window=0):
        """
        Returns whether fullscreen is enabled for the given window as bool.        
        """

        return self._browser_evaluate(
            expression=commands.gen_window_get_fullscreen_command(
                window_index=window,
            ),
        )

    @frontend_function
    @browser_function
    def set_fullscreen(self, window=0, fullscreen=True, decorations=True):
        """
        Enables or disables fullscreen mode for the given window.

        If decorations is set to `False`, the window decorations are not shown
        and the page is in "true" fullscreen mode.
        """

        self.logger.info(
            '%s fullscreen for window %s %s decorations',
            'enabling' if fullscreen else 'disabling',
            window,
            'with' if decorations else 'without',
        )

        return self._browser_evaluate(
            expression=commands.gen_window_set_fullscreen_command(
                window_index=window,
                fullscreen=fullscreen,
                decorations=decorations,
            ),
        )

    @frontend_function
    @browser_function
    def _get_url(self, window=0):
        return self._browser_evaluate(
            expression=commands.gen_window_get_url_command(
                window_index=window,
            ),
        )

    def get_url(self, window=0):
        """
        Returns the URL of the given window as a `milan.utils.url.URL` object.
        """

        raw_url = self._get_url(window=window)

        return URL(raw_url)

    # window
    @frontend_function
    @browser_function
    def get_window_size(self, window=0):
        """
        Returns the size of the given window.

        Example return value: `{'height': 720, 'width': 1_280}`
        """

        return self._browser_evaluate(
            expression=commands.gen_window_get_size_command(
                window_index=window,
            ),
        )

    def set_window_size(self, width, height, window=0, even_values=True):
        """
        Sets the size of the given window.

        If `even_values` is set to true, odd values get rounded to even
        numbers. This is necessary for some FFmpeg filters.
        """

        current_browser_size = self.get_size()
        current_window_size = self.get_window_size()

        width = width + (
            current_browser_size['width'] - current_window_size['width'])

        height = height + (
            current_browser_size['height'] - current_window_size['height'])

        return self.set_size(
            width=width,
            height=height,
            even_values=even_values,
        )

    # window: selectors
    @frontend_function
    @browser_function
    def await_load(self, window=0, url=''):
        raise NotImplementedError()

    @frontend_function
    @browser_function
    def element_exists(
            self,
            selector,
            element_index=0,
            retry_interval=None,
            timeout=None,
            window=0,
    ):

        """
        Checks whether at least one element matching the given selector is
        present in the given window. The selector is reevaluated in the given
        retry interval until the timeout is reached.

        If `element_index` is set, a matching element with the given index
        is awaited.

        If `retry_interval` is set to `None` the
        `Browser.short_selector_retry_interval` property is used instead.

        If `timeout` is set to `None` the
        `Browser.short_selector_timeout` property is used instead.
        """

        retry_interval = self._get_short_selector_retry_interval(
            retry_interval,
        )

        timeout = self._get_short_selector_timeout(timeout)

        self.logger.info(
            "checking if element with selector '%s' #%s in window %s exists with a timeout of %ss",  # NOQA
            selector,
            element_index,
            window,
            timeout,
        )

        _element_exists = self._browser_evaluate(
            expression=commands.gen_window_element_exists_command(
                window_index=window,
                selector=selector,
                element_index=element_index,
                retry_interval=retry_interval,
                timeout=timeout,
            ),
        )

        self.logger.info(
            "element with selector '%s' #%s %s in window %s",
            selector,
            element_index,
            'exists' if _element_exists else 'does not exist',
            window,
        )

        return _element_exists

    @frontend_function
    @browser_function
    def await_element(
            self,
            selector,
            element_index=0,
            retry_interval=None,
            timeout=None,
            window=0,
    ):

        """
        Waits for at least one element matching the given selector to be
        present in the given window. The selector is reevaluated in the given
        retry interval until the timeout is reached.
        If the timeout is reached, a `milan.FrontendError` is raised.

        If `element_index` is set, a matching element with the given index
        is awaited.

        If `retry_interval` is set to `None` the
        `Browser.selector_retry_interval` property is used instead.

        If `timeout` is set to `None` the
        `Browser.selector_timeout` property is used instead.

        !!! warning

            This method is deprecated and will be removed.

            Use `Browser.await_elements` instead.
        """

        retry_interval = self._get_selector_retry_interval(retry_interval)
        timeout = self._get_selector_timeout(timeout)

        self.logger.info(
            "waiting for element with selector '%s' #%s in window %s with a timeout of %ss",  # NOQA
            selector,
            element_index,
            window,
            timeout,
        )

        return self._browser_evaluate(
            expression=commands.gen_window_await_element_command(
                window_index=window,
                selector=selector,
                element_index=element_index,
                retry_interval=retry_interval,
                timeout=timeout,
            ),
        )

    @frontend_function
    @browser_function
    def await_elements(
            self,
            selectors,
            text='',
            present=True,
            match_all=True,
            count=None,
            index=None,
            retry_interval=None,
            timeout=None,
            window=0,
    ):

        """
        Waits for one or more selectors to match one or more elements in the
        given window and returns the matching selectors. All selectors are
        reevaluated in the given retry interval until the timeout is reached.
        If the timeout is reached, a `milan.FrontendError` is raised.

        If `text` is set to a string, all matching elements must have the
        given text.

        If `present` is set to `False`, the method waits until no matching
        element is present.

        If `match_all` is set to `False` only one of the given selectors
        has to match.

        If `count` is set to a number, the method will wait until the amount
        of matching elements is the given number.

        If `element_index` is set to a number, the method will wait until a
        matching element with that index is present, regardless the overall
        count.

        If `retry_interval` is set to `None` the
        `Browser.selector_retry_interval` property is used instead.

        If `timeout` is set to `None` the
        `Browser.selector_timeout` property is used instead.
        """

        retry_interval = self._get_selector_retry_interval(retry_interval)
        timeout = self._get_selector_timeout(timeout)

        if not isinstance(selectors, (list, tuple)):
            selectors = [selectors]

        self.logger.info(
            "waiting for %s with selectors '%s'%s in window %s to be %s [match_all=%s,timeout=%ss]",  # NOQA
            f'{count} element(s)' if count else 'element(s)',
            ','.join(selectors),
            f"and text '{text}'" if text else '',
            window,
            'present' if present else 'not present',
            match_all,
            timeout,
        )

        return self._browser_evaluate(
            expression=commands.gen_window_await_elements_command(
                window_index=window,
                selectors=selectors,
                text=text,
                present=present,
                match_all=match_all,
                count=count,
                index=index,
                retry_interval=retry_interval,
                timeout=timeout,
            ),
        )

    @frontend_function
    @browser_function
    def await_text(
            self,
            selector,
            text,
            element_index=0,
            retry_interval=None,
            timeout=None,
            window=0,
    ):

        """
        Waits for at least one element matching the given selector and text to
        be present in the given window. The selector is reevaluated in the
        given retry interval until the timeout is reached.
        If the timeout is reached, a `milan.FrontendError` is raised.

        If `element_index` is set, a matching element with the given index
        is awaited.

        If `retry_interval` is set to `None` the
        `Browser.selector_retry_interval` property is used instead.

        If `timeout` is set to `None` the
        `Browser.selector_timeout` property is used instead.

        !!! warning

            This method is deprecated and will be removed.

            Use `Browser.await_elements` instead.
        """

        retry_interval = self._get_selector_retry_interval(retry_interval)
        timeout = self._get_selector_timeout(timeout)

        self.logger.info(
            "waiting for element with selector '%s' #%s to contain '%s' in window %s with a timeout of %ss",  # NOQA
            selector,
            element_index,
            text,
            window,
            timeout,
        )

        return self._browser_evaluate(
            expression=commands.gen_window_await_text_command(
                window_index=window,
                selector=selector,
                element_index=element_index,
                text=text,
                retry_interval=retry_interval,
                timeout=timeout,
            ),
        )

    @frontend_function
    @browser_function
    def get_element_count(
            self,
            selector,
            window=0,
    ):

        """
        Returns the amount of elements matching the given selector in the
        given window as integer.
        """

        self.logger.info(
            "counting elements with selector '%s' in window %s",
            selector,
            window,
        )

        element_count = self._browser_evaluate(
            expression=commands.gen_window_get_element_count_command(
                window_index=window,
                selector=selector,
            ),
        )

        return element_count

    @frontend_function
    @browser_function
    def get_html(
            self,
            selector,
            element_index=0,
            retry_interval=None,
            timeout=None,
            window=0,
    ):

        """
        Waits for at least one element matching the given selector and returns
        its HTML as string.

        If `element_index` is set, a matching element with the given index
        is awaited and its value is returned.

        If `retry_interval` is set to `None` the
        `Browser.selector_retry_interval` property is used instead.

        If `timeout` is set to `None` the
        `Browser.selector_timeout` property is used instead.
        """

        retry_interval = self._get_selector_retry_interval(retry_interval)
        timeout = self._get_selector_timeout(timeout)

        self.logger.info(
            "getting HTML from element with selector '%s' #%s in window %s with a timeout of %ss",  # NOQA
            selector,
            element_index,
            window,
            timeout,
        )

        return self._browser_evaluate(
            expression=commands.gen_window_get_html_command(
                window_index=window,
                selector=selector,
                element_index=element_index,
                retry_interval=retry_interval,
                timeout=timeout,
            ),
        )

    @frontend_function
    @browser_function
    def set_html(
            self,
            selector,
            html,
            element_index=0,
            retry_interval=None,
            timeout=None,
            window=0,
    ):

        """
        Waits for at least one element matching the given selector and sets
        its HTML to the given string.

        If `element_index` is set, a matching element with the given index
        is awaited and its HTML is set.

        If `retry_interval` is set to `None` the
        `Browser.selector_retry_interval` property is used instead.

        If `timeout` is set to `None` the
        `Browser.selector_timeout` property is used instead.
        """

        retry_interval = self._get_selector_retry_interval(retry_interval)
        timeout = self._get_selector_timeout(timeout)

        self.logger.info(
            "setting HTML in element with selector '%s' #%s in window %s with a timeout of %ss",  # NOQA
            selector,
            element_index,
            window,
            timeout,
        )

        return self._browser_evaluate(
            expression=commands.gen_window_set_html_command(
                window_index=window,
                selector=selector,
                element_index=element_index,
                html=html,
                retry_interval=retry_interval,
                timeout=timeout,
            ),
        )

    @frontend_function
    @browser_function
    def get_text(
            self,
            selector,
            element_index=0,
            retry_interval=None,
            timeout=None,
            window=0,
    ):

        """
        Waits for at least one element matching the given selector and returns
        its text as string.

        If `element_index` is set, a matching element with the given index
        is awaited and its value is returned.

        If `retry_interval` is set to `None` the
        `Browser.selector_retry_interval` property is used instead.

        If `timeout` is set to `None` the
        `Browser.selector_timeout` property is used instead.
        """

        retry_interval = self._get_selector_retry_interval(retry_interval)
        timeout = self._get_selector_timeout(timeout)

        self.logger.info(
            "getting text from element with selector '%s' #%s in window %s with a timeout of %ss",  # NOQA
            selector,
            element_index,
            window,
            timeout,
        )

        return self._browser_evaluate(
            expression=commands.gen_window_get_text_command(
                window_index=window,
                selector=selector,
                element_index=element_index,
                retry_interval=retry_interval,
                timeout=timeout,
            ),
        )

    def set_text(
            self,
            selector,
            text,
            element_index=0,
            retry_interval=None,
            timeout=None,
            window=0,
    ):

        """
        Waits for at least one element matching the given selector and sets
        its text to the given string.

        If `element_index` is set, a matching element with the given index
        is awaited and its text is set.

        If `retry_interval` is set to `None` the
        `Browser.selector_retry_interval` property is used instead.

        If `timeout` is set to `None` the
        `Browser.selector_timeout` property is used instead.
        """

        return self.set_html(
            selector=selector,
            html=text,
            element_index=element_index,
            retry_interval=retry_interval,
            timeout=timeout,
            window=window,
        )

    @frontend_function
    @browser_function
    def get_attribute(
            self,
            selector,
            name,
            element_index=0,
            retry_interval=None,
            timeout=None,
            window=0,
    ):

        """
        Waits for at least one element matching the given selector and returns
        the attribute with the given name.

        If `element_index` is set, a matching element with the given index
        is awaited and its attributes are used.

        If `retry_interval` is set to `None` the
        `Browser.selector_retry_interval` property is used instead.

        If `timeout` is set to `None` the
        `Browser.selector_timeout` property is used instead.
        """

        retry_interval = self._get_selector_retry_interval(retry_interval)
        timeout = self._get_selector_timeout(timeout)

        self.logger.info(
            "getting attribute '%s' from element with selector '%s' #%s in window %s with a timeout of %ss",  # NOQA
            name,
            selector,
            element_index,
            window,
            timeout,
        )

        return self._browser_evaluate(
            expression=commands.gen_window_get_attribute_command(
                window_index=window,
                selector=selector,
                element_index=element_index,
                name=name,
                retry_interval=retry_interval,
                timeout=timeout,
            ),
        )

    @frontend_function
    @browser_function
    def get_attributes(
            self,
            selector,
            element_index=0,
            retry_interval=None,
            timeout=None,
            window=0,
    ):

        """
        Waits for at least one element matching the given selector and returns
        all of its attributes as a dict.

        If `element_index` is set, a matching element with the given index
        is awaited and its attributes are returned.

        If `retry_interval` is set to `None` the
        `Browser.selector_retry_interval` property is used instead.

        If `timeout` is set to `None` the
        `Browser.selector_timeout` property is used instead.
        """

        retry_interval = self._get_selector_retry_interval(retry_interval)
        timeout = self._get_selector_timeout(timeout)

        self.logger.info(
            "getting attributes of element with selector '%s' #%s in window %s with a timeout of %ss",  # NOQA
            selector,
            element_index,
            window,
            timeout,
        )

        return self._browser_evaluate(
            expression=commands.gen_window_get_attributes_command(
                window_index=window,
                selector=selector,
                element_index=element_index,
                retry_interval=retry_interval,
                timeout=timeout,
            ),
        )

    @frontend_function
    @browser_function
    def set_attributes(
            self,
            selector,
            attributes,
            element_index=0,
            retry_interval=None,
            timeout=None,
            window=0,
    ):

        """
        Waits for at least one element matching the given selector and sets
        the given attributes provided as a dict.

        If `element_index` is set, a matching element with the given index
        is awaited and its attributes are set.

        If `retry_interval` is set to `None` the
        `Browser.selector_retry_interval` property is used instead.

        If `timeout` is set to `None` the
        `Browser.selector_timeout` property is used instead.
        """

        retry_interval = self._get_selector_retry_interval(retry_interval)
        timeout = self._get_selector_timeout(timeout)

        self.logger.info(
            "setting attributes of element with selector '%s' #%s in window %s with a timeout of %ss",  # NOQA
            selector,
            element_index,
            window,
            timeout,
        )

        return self._browser_evaluate(
            expression=commands.gen_window_set_attributes_command(
                window_index=window,
                selector=selector,
                element_index=element_index,
                attributes=attributes,
                retry_interval=retry_interval,
                timeout=timeout,
            ),
        )

    def set_attribute(
            self,
            selector,
            name,
            value,
            element_index=0,
            retry_interval=None,
            timeout=None,
            window=0,
    ):

        """
        Waits for at least one element matching the given selector and sets
        the given attribute name to the given value.

        If `element_index` is set, a matching element with the given index
        is awaited and its attributes are used.

        If `retry_interval` is set to `None` the
        `Browser.selector_retry_interval` property is used instead.

        If `timeout` is set to `None` the
        `Browser.selector_timeout` property is used instead.
        """

        return self.set_attributes(
            selector=selector,
            element_index=element_index,
            attributes={name: value},
            retry_interval=retry_interval,
            timeout=timeout,
            window=window,
        )

    @frontend_function
    @browser_function
    def remove_attributes(
            self,
            selector,
            names,
            element_index=0,
            retry_interval=None,
            timeout=None,
            window=0,
    ):

        """
        Waits for at least one element matching the given selector and removes
        the given attribute names.

        If `element_index` is set, a matching element with the given index
        is awaited and its attributes are used.

        If `retry_interval` is set to `None` the
        `Browser.selector_retry_interval` property is used instead.

        If `timeout` is set to `None` the
        `Browser.selector_timeout` property is used instead.
        """

        retry_interval = self._get_selector_retry_interval(retry_interval)
        timeout = self._get_selector_timeout(timeout)

        self.logger.info(
            "removing attributes '%s' of element with selector '%s' #%s in window %s with a timeout of %ss",  # NOQA
            names,
            selector,
            element_index,
            window,
            timeout,
        )

        return self._browser_evaluate(
            expression=commands.gen_window_remove_attributes_command(
                window_index=window,
                selector=selector,
                element_index=element_index,
                names=names,
                retry_interval=retry_interval,
                timeout=timeout,
            ),
        )

    def remove_attribute(
            self,
            selector,
            name,
            element_index=0,
            retry_interval=None,
            timeout=None,
            window=0,
    ):

        """
        Waits for at least one element matching the given selector and removes
        the given attribute name.

        If `element_index` is set, a matching element with the given index
        is awaited and its attributes are used.

        If `retry_interval` is set to `None` the
        `Browser.selector_retry_interval` property is used instead.

        If `timeout` is set to `None` the
        `Browser.selector_timeout` property is used instead.
        """

        return self.remove_attributes(
            selector=selector,
            names=[name],
            element_index=element_index,
            retry_interval=retry_interval,
            timeout=timeout,
            window=window,
        )

    def get_class_list(
            self,
            selector,
            element_index=0,
            retry_interval=None,
            timeout=None,
            window=0,
    ):

        """
        Waits for at least one element matching the given selector and returns
        its CSS class list as a list of strings.

        If `element_index` is set, a matching element with the given index
        is awaited and its attributes are used.

        If `retry_interval` is set to `None` the
        `Browser.selector_retry_interval` property is used instead.

        If `timeout` is set to `None` the
        `Browser.selector_timeout` property is used instead.
        """

        class_list = self.get_attribute(
            selector=selector,
            element_index=element_index,
            name='class',
            retry_interval=retry_interval,
            timeout=timeout,
            window=window,
        ).split(' ')

        return [i for i in class_list if i]

    def set_class_list(
            self,
            selector,
            names,
            element_index=0,
            retry_interval=None,
            timeout=None,
            window=0,
    ):

        """
        Waits for at least one element matching the given selector and sets
        its CSS class list to the given list of strings.

        If `element_index` is set, a matching element with the given index
        is awaited and its attributes are used.

        If `retry_interval` is set to `None` the
        `Browser.selector_retry_interval` property is used instead.

        If `timeout` is set to `None` the
        `Browser.selector_timeout` property is used instead.
        """

        return self.set_attribute(
            selector=selector,
            name='class',
            value=' '.join(names),
            element_index=element_index,
            retry_interval=retry_interval,
            timeout=timeout,
            window=window,
        )

    def clear_class_list(
            self,
            selector,
            element_index=0,
            retry_interval=None,
            timeout=None,
            window=0,
    ):

        """
        Waits for at least one element matching the given selector and clears
        its CSS class list.

        If `element_index` is set, a matching element with the given index
        is awaited and its attributes are used.

        If `retry_interval` is set to `None` the
        `Browser.selector_retry_interval` property is used instead.

        If `timeout` is set to `None` the
        `Browser.selector_timeout` property is used instead.
        """

        return self.set_attribute(
            selector=selector,
            name='class',
            value='',
            element_index=element_index,
            retry_interval=retry_interval,
            timeout=timeout,
            window=window,
        )

    @frontend_function
    @browser_function
    def class_list_add(
            self,
            selector,
            names,
            element_index=0,
            retry_interval=None,
            timeout=None,
            window=0,
    ):

        """
        Waits for at least one element matching the given selector and adds
        the given class to its CSS class list.

        If `element_index` is set, a matching element with the given index
        is awaited and its attributes are used.

        If `retry_interval` is set to `None` the
        `Browser.selector_retry_interval` property is used instead.

        If `timeout` is set to `None` the
        `Browser.selector_timeout` property is used instead.
        """

        retry_interval = self._get_selector_retry_interval(retry_interval)
        timeout = self._get_selector_timeout(timeout)

        if not isinstance(names, (list, tuple)):
            names = [names]

        self.logger.info(
            "adding classs '%s' to element with selector '%s' #%s in window %s with a timeout of %ss",  # NOQA
            repr(names),
            selector,
            element_index,
            window,
            timeout,
        )

        return self._browser_evaluate(
            expression=commands.gen_window_class_list_add_command(
                window_index=window,
                selector=selector,
                element_index=element_index,
                names=names,
                retry_interval=retry_interval,
                timeout=timeout,
            ),
        )

    @frontend_function
    @browser_function
    def class_list_remove(
            self,
            selector,
            names,
            element_index=0,
            retry_interval=None,
            timeout=None,
            window=0,
    ):

        """
        Waits for at least one element matching the given selector and removes
        the given class from its CSS class list.

        If `element_index` is set, a matching element with the given index
        is awaited and its attributes are used.

        If `retry_interval` is set to `None` the
        `Browser.selector_retry_interval` property is used instead.

        If `timeout` is set to `None` the
        `Browser.selector_timeout` property is used instead.
        """

        retry_interval = self._get_selector_retry_interval(retry_interval)
        timeout = self._get_selector_timeout(timeout)

        if not isinstance(names, (list, tuple)):
            names = [names]

        self.logger.info(
            "removing classes '%s' from element with selector '%s' #%s in window %s with a timeout of %ss",  # NOQA
            repr(names),
            selector,
            element_index,
            window,
            timeout,
        )

        return self._browser_evaluate(
            expression=commands.gen_window_class_list_remove_command(
                window_index=window,
                selector=selector,
                element_index=element_index,
                names=names,
                retry_interval=retry_interval,
                timeout=timeout,
            ),
        )

    # window: user input
    @frontend_function
    @browser_function
    def click(
            self,
            selector,
            element_index=0,
            retry_interval=None,
            timeout=None,
            animation=None,
            window=0,
    ):

        """
        Waits for at least one element matching the given selector and fires
        a click event onto it.

        If `animation` is set to true, an animation using the cursor is played.
        If animation is set to `None` the `Browser.animation` property is used
        to determine if an animation should be played.

        If `element_index` is set, a matching element with the given index
        is awaited and its attributes are used.

        If `retry_interval` is set to `None` the
        `Browser.selector_retry_interval` property is used instead.

        If `timeout` is set to `None` the
        `Browser.selector_timeout` property is used instead.
        """

        retry_interval = self._get_selector_retry_interval(retry_interval)
        timeout = self._get_selector_timeout(timeout)

        self.logger.info(
            "clicking on element with selector '%s' #%s in window %s with a timeout of %ss",  # NOQA
            selector,
            element_index,
            window,
            timeout,
        )

        return self._browser_evaluate(
            expression=commands.gen_window_click_command(
                window_index=window,
                selector=selector,
                element_index=element_index,
                retry_interval=retry_interval,
                timeout=timeout,
                animation=self._get_animations(animation),
            ),
        )

    @frontend_function
    @browser_function
    def fill(
            self,
            selector,
            value,
            element_index=0,
            retry_interval=None,
            timeout=None,
            animation=None,
            window=0,
    ):

        """
        Waits for at least one input matching the given selector and fills the
        given value into it.

        If `animation` is set to true, an animation using the cursor is played.
        If animation is set to `None` the `Browser.animation` property is used
        to determine if an animation should be played.

        If `element_index` is set, a matching element with the given index
        is awaited and its attributes are used.

        If `retry_interval` is set to `None` the
        `Browser.selector_retry_interval` property is used instead.

        If `timeout` is set to `None` the
        `Browser.selector_timeout` property is used instead.
        """

        retry_interval = self._get_selector_retry_interval(retry_interval)
        timeout = self._get_selector_timeout(timeout)

        self.logger.info(
            "filling value '%s' #%s into an element with selector '%s' in window %s with a timeout of %ss",  # NOQA
            value,
            selector,
            element_index,
            window,
            timeout,
        )

        return self._browser_evaluate(
            expression=commands.gen_window_fill_command(
                window_index=window,
                selector=selector,
                element_index=element_index,
                value=value,
                retry_interval=retry_interval,
                timeout=timeout,
                animation=self._get_animations(animation),
            ),
        )

    @frontend_function
    @browser_function
    def check(
            self,
            selector,
            value=True,
            element_index=0,
            retry_interval=None,
            timeout=None,
            animation=None,
            window=0,
    ):

        """
        Waits for at least one checkbox matching the given selector and checks
        or unchecks it, depending on the given value.

        If `animation` is set to true, an animation using the cursor is played.
        If animation is set to `None` the `Browser.animation` property is used
        to determine if an animation should be played.

        If `element_index` is set, a matching element with the given index
        is awaited and its attributes are used.

        If `retry_interval` is set to `None` the
        `Browser.selector_retry_interval` property is used instead.

        If `timeout` is set to `None` the
        `Browser.selector_timeout` property is used instead.
        """

        retry_interval = self._get_selector_retry_interval(retry_interval)
        timeout = self._get_selector_timeout(timeout)

        self.logger.info(
            "%s checkbox with selector '%s' #%s in window %s with a timeout of %ss",  # NOQA
            'checking' if value else 'unchecking',
            selector,
            element_index,
            window,
            timeout,
        )

        return self._browser_evaluate(
            expression=commands.gen_window_check_command(
                window_index=window,
                selector=selector,
                element_index=element_index,
                value=value,
                retry_interval=retry_interval,
                timeout=timeout,
                animation=self._get_animations(animation),
            ),
        )

    @frontend_function
    @browser_function
    def select(
            self,
            selector,
            element_index=0,
            value=None,
            index=None,
            label=None,
            retry_interval=None,
            timeout=None,
            window=0,
            animation=None,
    ):

        """
        Waits for at least one select element matching the given selector and
        selects an option specified by `value`, `index`, or `label`.

        If `animation` is set to true, an animation using the cursor is played.
        If animation is set to `None` the `Browser.animation` property is used
        to determine if an animation should be played.

        If `element_index` is set, a matching element with the given index
        is awaited and its attributes are used.

        If `retry_interval` is set to `None` the
        `Browser.selector_retry_interval` property is used instead.

        If `timeout` is set to `None` the
        `Browser.selector_timeout` property is used instead.
        """

        retry_interval = self._get_selector_retry_interval(retry_interval)
        timeout = self._get_selector_timeout(timeout)

        identifier = ''

        if value:
            identifier = f"value '{value}'"

        elif value:
            identifier = f"index '{index}'"

        elif label:
            identifier = f"label '{label}'"

        self.logger.info(
            "selecting option with %s in select with selector '%s' #%s in window %s with a timeout of %ss",  # NOQA
            identifier,
            selector,
            element_index,
            window,
            timeout,
        )

        return self._browser_evaluate(
            expression=commands.gen_window_select_command(
                window_index=window,
                selector=selector,
                element_index=element_index,
                value=value,
                index=index,
                label=label,
                retry_interval=retry_interval,
                timeout=timeout,
                animation=self._get_animations(animation),
            ),
        )

    # navigation ##############################################################
    @browser_function
    @frontend_function
    def navigate(self, url, window=0, animation=None):
        """
        Navigates the given window to the given URL.

        If `animation` is set to true, an animation is played that uses the
        cursor to click and fill the address bar of the window.

        If `animation` is set to `None` the `Browser.animation` property is
        used to determine if an animation should be played.
        """

        # TODO: add support for external sites besides 'localhost'
        # TODO: add support for cursor bootstrapping

        url = URL(url)

        # rewrite 'localhost' to '127.0.0.1' to prevent cookie settings loops
        # between the two origins (the frontend runs on '127.0.0.1')
        if url.host == 'localhost':
            url.host = '127.0.0.1'

        self.logger.info('navigating frontend to %s', url)

        return self._browser_evaluate(
            expression=commands.gen_window_navigate_command(
                window_index=window,
                url=str(url),
                animation=self._get_animations(animation),
            ),
        )

    def navigate_to_test_application(self, *args, **kwargs):
        """
        Navigates the given window to the Milan test application.
        """

        return self.navigate(
            url=self._frontend_server.get_test_application_url(),
            *args,
            **kwargs,
        )

    @browser_function
    def reload_frontend(self):
        """
        Reloads the Milan frontend.
        """

        self.logger.info('loading frontend')

        self._browser_navigate(url=self._frontend_server.get_frontend_url())

    @browser_function
    @frontend_function
    def highlight_elements(
        self,
        selectors,
        index=None,
        count=None,
        retry_interval=None,
        timeout=None,
        border_width=2,
        border_style='solid',
        border_color='#FF0000',
        padding=10,
        track=True,
        duration=None,
        window=0,
    ):

        """
        Waits for at least one element matching the given selector and
        selects and draws a marker around it.

        If `duration` is set to a number, the method will block for the given
        duration and the highlights will be removed afterwards.

        If `track` is set to true, the marker will track possible movements
        of the highlighted element.

        If `element_index` is set, a matching element with the given index
        is awaited and its attributes are used.

        If `retry_interval` is set to `None` the
        `Browser.selector_retry_interval` property is used instead.

        If `timeout` is set to `None` the
        `Browser.selector_timeout` property is used instead.
        """

        retry_interval = self._get_selector_retry_interval(retry_interval)
        timeout = self._get_selector_timeout(timeout)

        if not isinstance(selectors, (list, tuple)):
            selectors = [selectors]

        return self._browser_evaluate(
            expression=commands.gen_window_highlight_elements_command(
                window_index=window,
                selectors=selectors,
                index=index,
                count=count,
                retry_interval=retry_interval,
                timeout=timeout,
                border_width=border_width,
                border_style=border_style,
                border_color=border_color,
                padding=padding,
                track=track,
                duration=duration,
            ),
        )

    @browser_function
    @frontend_function
    def remove_highlights(self, window=0):
        """
        Removes all highlight markers in the given window.
        """

        return self._browser_evaluate(
            expression=commands.gen_window_remove_highlights_command(
                window_index=window,
            ),
        )

    # hooks ###################################################################
    @browser_function
    def _browser_navigate(self, url):
        raise NotImplementedError()

    @browser_function
    def _browser_evaluate(self, expression):
        raise NotImplementedError()

    @browser_function
    def _browser_set_size(self, width, height):
        raise NotImplementedError()

    def stop(self):
        """
        Stops the browser.

        When video capturing is still running, `Browser.stop_video_capturing`
        is called automatically.
        """

        raise NotImplementedError()

    def set_color_scheme(self, color_scheme):
        """
        Sets the color scheme of the browser.

        Possible values:
          - light
          - dark
        """

        raise NotImplementedError()

    @browser_function
    def screenshot(self, path):
        """
        Writes a screenshot of the current page to the given path.
        """

        raise NotImplementedError()

    @browser_function
    def start_video_capturing(
            self,
            path,
            delay=DEFAULT_VIDEO_CAPTURING_START_DELAY,
    ):

        """
        Starts video capturing into the given path.

        The video format is determined by the file extension of the given
        path.

        Possible video formats:
          - webm
          - mp4
          - gif
        """

        raise NotImplementedError()

    @browser_function
    def stop_video_capturing(
            self,
            delay=DEFAULT_VIDEO_CAPTURING_STOP_DELAY,
    ):

        raise NotImplementedError()

add_style_sheet(text, window=0)

Adds a CSS stylesheet as text to the given window.

Source code in milan/browser.py
@browser_function
@frontend_function
def add_style_sheet(self, text, window=0):
    """
    Adds a CSS stylesheet as text to the given window.
    """

    # add to browser
    if window is None:
        return self._browser_evaluate(
            expression=commands.gen_add_style_sheet_command(
                text=text,
            ),
        )

    # add to window
    return self._browser_evaluate(
        expression=commands.gen_window_add_style_sheet_command(
            window_index=window,
            text=text,
        ),
    )

await_browser_load(timeout=None, await_future=True)

Waits for the next JavaScript window load event (window.onload).

timeout can be a positive number in seconds or None. If the is None, the default timeout is used.

If await_future is true, the method blocks until the next event gets fired. If not, a concurrent.futures.Future object is returned that can be awaited outside the method.

Source code in milan/browser.py
@browser_function
def await_browser_load(self, timeout=None, await_future=True):
    """
    Waits for the next JavaScript window load event (`window.onload`).

    `timeout` can be a positive number in seconds or `None`. If the is
    `None`, the default timeout is used.

    If `await_future` is true, the method blocks until the next event gets
    fired. If not, a `concurrent.futures.Future` object is returned that
    can be awaited outside the method.
    """

    return self._event_router.await_event(
        name='browser_load',
        timeout=timeout,
        await_future=await_future,
    )

await_browser_navigation(url=None, timeout=None, await_future=True)

Waits for the next navigation event of the browser.

If url is set, the browser waits until the given URL is present.

timeout can be a positive number in seconds or None. If the is None, the default timeout is used.

If await_future is true, the method blocks until the next event gets fired. If not, a concurrent.futures.Future object is returned that can be awaited outside the method.

Source code in milan/browser.py
@browser_function
def await_browser_navigation(
        self,
        url=None,
        timeout=None,
        await_future=True,
):

    """
    Waits for the next navigation event of the browser.

    If `url` is set, the browser waits until the given URL is present.

    `timeout` can be a positive number in seconds or `None`. If the is
    `None`, the default timeout is used.

    If `await_future` is true, the method blocks until the next event gets
    fired. If not, a `concurrent.futures.Future` object is returned that
    can be awaited outside the method.
    """

    if url:
        return self._event_router.await_state(
            name='browser_url',
            value=URL.normalize(url),
            timeout=timeout,
            await_future=await_future,
        )

    return self._event_router.await_event(
        name='browser_navigation',
        timeout=timeout,
        await_future=await_future,
    )

await_element(selector, element_index=0, retry_interval=None, timeout=None, window=0)

Waits for at least one element matching the given selector to be present in the given window. The selector is reevaluated in the given retry interval until the timeout is reached. If the timeout is reached, a milan.FrontendError is raised.

If element_index is set, a matching element with the given index is awaited.

If retry_interval is set to None the Browser.selector_retry_interval property is used instead.

If timeout is set to None the Browser.selector_timeout property is used instead.

Warning

This method is deprecated and will be removed.

Use Browser.await_elements instead.

Source code in milan/browser.py
@frontend_function
@browser_function
def await_element(
        self,
        selector,
        element_index=0,
        retry_interval=None,
        timeout=None,
        window=0,
):

    """
    Waits for at least one element matching the given selector to be
    present in the given window. The selector is reevaluated in the given
    retry interval until the timeout is reached.
    If the timeout is reached, a `milan.FrontendError` is raised.

    If `element_index` is set, a matching element with the given index
    is awaited.

    If `retry_interval` is set to `None` the
    `Browser.selector_retry_interval` property is used instead.

    If `timeout` is set to `None` the
    `Browser.selector_timeout` property is used instead.

    !!! warning

        This method is deprecated and will be removed.

        Use `Browser.await_elements` instead.
    """

    retry_interval = self._get_selector_retry_interval(retry_interval)
    timeout = self._get_selector_timeout(timeout)

    self.logger.info(
        "waiting for element with selector '%s' #%s in window %s with a timeout of %ss",  # NOQA
        selector,
        element_index,
        window,
        timeout,
    )

    return self._browser_evaluate(
        expression=commands.gen_window_await_element_command(
            window_index=window,
            selector=selector,
            element_index=element_index,
            retry_interval=retry_interval,
            timeout=timeout,
        ),
    )

await_elements(selectors, text='', present=True, match_all=True, count=None, index=None, retry_interval=None, timeout=None, window=0)

Waits for one or more selectors to match one or more elements in the given window and returns the matching selectors. All selectors are reevaluated in the given retry interval until the timeout is reached. If the timeout is reached, a milan.FrontendError is raised.

If text is set to a string, all matching elements must have the given text.

If present is set to False, the method waits until no matching element is present.

If match_all is set to False only one of the given selectors has to match.

If count is set to a number, the method will wait until the amount of matching elements is the given number.

If element_index is set to a number, the method will wait until a matching element with that index is present, regardless the overall count.

If retry_interval is set to None the Browser.selector_retry_interval property is used instead.

If timeout is set to None the Browser.selector_timeout property is used instead.

Source code in milan/browser.py
@frontend_function
@browser_function
def await_elements(
        self,
        selectors,
        text='',
        present=True,
        match_all=True,
        count=None,
        index=None,
        retry_interval=None,
        timeout=None,
        window=0,
):

    """
    Waits for one or more selectors to match one or more elements in the
    given window and returns the matching selectors. All selectors are
    reevaluated in the given retry interval until the timeout is reached.
    If the timeout is reached, a `milan.FrontendError` is raised.

    If `text` is set to a string, all matching elements must have the
    given text.

    If `present` is set to `False`, the method waits until no matching
    element is present.

    If `match_all` is set to `False` only one of the given selectors
    has to match.

    If `count` is set to a number, the method will wait until the amount
    of matching elements is the given number.

    If `element_index` is set to a number, the method will wait until a
    matching element with that index is present, regardless the overall
    count.

    If `retry_interval` is set to `None` the
    `Browser.selector_retry_interval` property is used instead.

    If `timeout` is set to `None` the
    `Browser.selector_timeout` property is used instead.
    """

    retry_interval = self._get_selector_retry_interval(retry_interval)
    timeout = self._get_selector_timeout(timeout)

    if not isinstance(selectors, (list, tuple)):
        selectors = [selectors]

    self.logger.info(
        "waiting for %s with selectors '%s'%s in window %s to be %s [match_all=%s,timeout=%ss]",  # NOQA
        f'{count} element(s)' if count else 'element(s)',
        ','.join(selectors),
        f"and text '{text}'" if text else '',
        window,
        'present' if present else 'not present',
        match_all,
        timeout,
    )

    return self._browser_evaluate(
        expression=commands.gen_window_await_elements_command(
            window_index=window,
            selectors=selectors,
            text=text,
            present=present,
            match_all=match_all,
            count=count,
            index=index,
            retry_interval=retry_interval,
            timeout=timeout,
        ),
    )

await_text(selector, text, element_index=0, retry_interval=None, timeout=None, window=0)

Waits for at least one element matching the given selector and text to be present in the given window. The selector is reevaluated in the given retry interval until the timeout is reached. If the timeout is reached, a milan.FrontendError is raised.

If element_index is set, a matching element with the given index is awaited.

If retry_interval is set to None the Browser.selector_retry_interval property is used instead.

If timeout is set to None the Browser.selector_timeout property is used instead.

Warning

This method is deprecated and will be removed.

Use Browser.await_elements instead.

Source code in milan/browser.py
@frontend_function
@browser_function
def await_text(
        self,
        selector,
        text,
        element_index=0,
        retry_interval=None,
        timeout=None,
        window=0,
):

    """
    Waits for at least one element matching the given selector and text to
    be present in the given window. The selector is reevaluated in the
    given retry interval until the timeout is reached.
    If the timeout is reached, a `milan.FrontendError` is raised.

    If `element_index` is set, a matching element with the given index
    is awaited.

    If `retry_interval` is set to `None` the
    `Browser.selector_retry_interval` property is used instead.

    If `timeout` is set to `None` the
    `Browser.selector_timeout` property is used instead.

    !!! warning

        This method is deprecated and will be removed.

        Use `Browser.await_elements` instead.
    """

    retry_interval = self._get_selector_retry_interval(retry_interval)
    timeout = self._get_selector_timeout(timeout)

    self.logger.info(
        "waiting for element with selector '%s' #%s to contain '%s' in window %s with a timeout of %ss",  # NOQA
        selector,
        element_index,
        text,
        window,
        timeout,
    )

    return self._browser_evaluate(
        expression=commands.gen_window_await_text_command(
            window_index=window,
            selector=selector,
            element_index=element_index,
            text=text,
            retry_interval=retry_interval,
            timeout=timeout,
        ),
    )

check(selector, value=True, element_index=0, retry_interval=None, timeout=None, animation=None, window=0)

Waits for at least one checkbox matching the given selector and checks or unchecks it, depending on the given value.

If animation is set to true, an animation using the cursor is played. If animation is set to None the Browser.animation property is used to determine if an animation should be played.

If element_index is set, a matching element with the given index is awaited and its attributes are used.

If retry_interval is set to None the Browser.selector_retry_interval property is used instead.

If timeout is set to None the Browser.selector_timeout property is used instead.

Source code in milan/browser.py
@frontend_function
@browser_function
def check(
        self,
        selector,
        value=True,
        element_index=0,
        retry_interval=None,
        timeout=None,
        animation=None,
        window=0,
):

    """
    Waits for at least one checkbox matching the given selector and checks
    or unchecks it, depending on the given value.

    If `animation` is set to true, an animation using the cursor is played.
    If animation is set to `None` the `Browser.animation` property is used
    to determine if an animation should be played.

    If `element_index` is set, a matching element with the given index
    is awaited and its attributes are used.

    If `retry_interval` is set to `None` the
    `Browser.selector_retry_interval` property is used instead.

    If `timeout` is set to `None` the
    `Browser.selector_timeout` property is used instead.
    """

    retry_interval = self._get_selector_retry_interval(retry_interval)
    timeout = self._get_selector_timeout(timeout)

    self.logger.info(
        "%s checkbox with selector '%s' #%s in window %s with a timeout of %ss",  # NOQA
        'checking' if value else 'unchecking',
        selector,
        element_index,
        window,
        timeout,
    )

    return self._browser_evaluate(
        expression=commands.gen_window_check_command(
            window_index=window,
            selector=selector,
            element_index=element_index,
            value=value,
            retry_interval=retry_interval,
            timeout=timeout,
            animation=self._get_animations(animation),
        ),
    )

class_list_add(selector, names, element_index=0, retry_interval=None, timeout=None, window=0)

Waits for at least one element matching the given selector and adds the given class to its CSS class list.

If element_index is set, a matching element with the given index is awaited and its attributes are used.

If retry_interval is set to None the Browser.selector_retry_interval property is used instead.

If timeout is set to None the Browser.selector_timeout property is used instead.

Source code in milan/browser.py
@frontend_function
@browser_function
def class_list_add(
        self,
        selector,
        names,
        element_index=0,
        retry_interval=None,
        timeout=None,
        window=0,
):

    """
    Waits for at least one element matching the given selector and adds
    the given class to its CSS class list.

    If `element_index` is set, a matching element with the given index
    is awaited and its attributes are used.

    If `retry_interval` is set to `None` the
    `Browser.selector_retry_interval` property is used instead.

    If `timeout` is set to `None` the
    `Browser.selector_timeout` property is used instead.
    """

    retry_interval = self._get_selector_retry_interval(retry_interval)
    timeout = self._get_selector_timeout(timeout)

    if not isinstance(names, (list, tuple)):
        names = [names]

    self.logger.info(
        "adding classs '%s' to element with selector '%s' #%s in window %s with a timeout of %ss",  # NOQA
        repr(names),
        selector,
        element_index,
        window,
        timeout,
    )

    return self._browser_evaluate(
        expression=commands.gen_window_class_list_add_command(
            window_index=window,
            selector=selector,
            element_index=element_index,
            names=names,
            retry_interval=retry_interval,
            timeout=timeout,
        ),
    )

class_list_remove(selector, names, element_index=0, retry_interval=None, timeout=None, window=0)

Waits for at least one element matching the given selector and removes the given class from its CSS class list.

If element_index is set, a matching element with the given index is awaited and its attributes are used.

If retry_interval is set to None the Browser.selector_retry_interval property is used instead.

If timeout is set to None the Browser.selector_timeout property is used instead.

Source code in milan/browser.py
@frontend_function
@browser_function
def class_list_remove(
        self,
        selector,
        names,
        element_index=0,
        retry_interval=None,
        timeout=None,
        window=0,
):

    """
    Waits for at least one element matching the given selector and removes
    the given class from its CSS class list.

    If `element_index` is set, a matching element with the given index
    is awaited and its attributes are used.

    If `retry_interval` is set to `None` the
    `Browser.selector_retry_interval` property is used instead.

    If `timeout` is set to `None` the
    `Browser.selector_timeout` property is used instead.
    """

    retry_interval = self._get_selector_retry_interval(retry_interval)
    timeout = self._get_selector_timeout(timeout)

    if not isinstance(names, (list, tuple)):
        names = [names]

    self.logger.info(
        "removing classes '%s' from element with selector '%s' #%s in window %s with a timeout of %ss",  # NOQA
        repr(names),
        selector,
        element_index,
        window,
        timeout,
    )

    return self._browser_evaluate(
        expression=commands.gen_window_class_list_remove_command(
            window_index=window,
            selector=selector,
            element_index=element_index,
            names=names,
            retry_interval=retry_interval,
            timeout=timeout,
        ),
    )

clear_class_list(selector, element_index=0, retry_interval=None, timeout=None, window=0)

Waits for at least one element matching the given selector and clears its CSS class list.

If element_index is set, a matching element with the given index is awaited and its attributes are used.

If retry_interval is set to None the Browser.selector_retry_interval property is used instead.

If timeout is set to None the Browser.selector_timeout property is used instead.

Source code in milan/browser.py
def clear_class_list(
        self,
        selector,
        element_index=0,
        retry_interval=None,
        timeout=None,
        window=0,
):

    """
    Waits for at least one element matching the given selector and clears
    its CSS class list.

    If `element_index` is set, a matching element with the given index
    is awaited and its attributes are used.

    If `retry_interval` is set to `None` the
    `Browser.selector_retry_interval` property is used instead.

    If `timeout` is set to `None` the
    `Browser.selector_timeout` property is used instead.
    """

    return self.set_attribute(
        selector=selector,
        name='class',
        value='',
        element_index=element_index,
        retry_interval=retry_interval,
        timeout=timeout,
        window=window,
    )

click(selector, element_index=0, retry_interval=None, timeout=None, animation=None, window=0)

Waits for at least one element matching the given selector and fires a click event onto it.

If animation is set to true, an animation using the cursor is played. If animation is set to None the Browser.animation property is used to determine if an animation should be played.

If element_index is set, a matching element with the given index is awaited and its attributes are used.

If retry_interval is set to None the Browser.selector_retry_interval property is used instead.

If timeout is set to None the Browser.selector_timeout property is used instead.

Source code in milan/browser.py
@frontend_function
@browser_function
def click(
        self,
        selector,
        element_index=0,
        retry_interval=None,
        timeout=None,
        animation=None,
        window=0,
):

    """
    Waits for at least one element matching the given selector and fires
    a click event onto it.

    If `animation` is set to true, an animation using the cursor is played.
    If animation is set to `None` the `Browser.animation` property is used
    to determine if an animation should be played.

    If `element_index` is set, a matching element with the given index
    is awaited and its attributes are used.

    If `retry_interval` is set to `None` the
    `Browser.selector_retry_interval` property is used instead.

    If `timeout` is set to `None` the
    `Browser.selector_timeout` property is used instead.
    """

    retry_interval = self._get_selector_retry_interval(retry_interval)
    timeout = self._get_selector_timeout(timeout)

    self.logger.info(
        "clicking on element with selector '%s' #%s in window %s with a timeout of %ss",  # NOQA
        selector,
        element_index,
        window,
        timeout,
    )

    return self._browser_evaluate(
        expression=commands.gen_window_click_command(
            window_index=window,
            selector=selector,
            element_index=element_index,
            retry_interval=retry_interval,
            timeout=timeout,
            animation=self._get_animations(animation),
        ),
    )

cursor_is_visible()

Returns whether the cursor is visible as bool.

Source code in milan/browser.py
@frontend_function
@browser_function
def cursor_is_visible(self):
    """
    Returns whether the cursor is visible as bool.
    """

    return self._browser_evaluate(
        expression=commands.gen_cursor_is_visible_command(),
    )

element_exists(selector, element_index=0, retry_interval=None, timeout=None, window=0)

Checks whether at least one element matching the given selector is present in the given window. The selector is reevaluated in the given retry interval until the timeout is reached.

If element_index is set, a matching element with the given index is awaited.

If retry_interval is set to None the Browser.short_selector_retry_interval property is used instead.

If timeout is set to None the Browser.short_selector_timeout property is used instead.

Source code in milan/browser.py
@frontend_function
@browser_function
def element_exists(
        self,
        selector,
        element_index=0,
        retry_interval=None,
        timeout=None,
        window=0,
):

    """
    Checks whether at least one element matching the given selector is
    present in the given window. The selector is reevaluated in the given
    retry interval until the timeout is reached.

    If `element_index` is set, a matching element with the given index
    is awaited.

    If `retry_interval` is set to `None` the
    `Browser.short_selector_retry_interval` property is used instead.

    If `timeout` is set to `None` the
    `Browser.short_selector_timeout` property is used instead.
    """

    retry_interval = self._get_short_selector_retry_interval(
        retry_interval,
    )

    timeout = self._get_short_selector_timeout(timeout)

    self.logger.info(
        "checking if element with selector '%s' #%s in window %s exists with a timeout of %ss",  # NOQA
        selector,
        element_index,
        window,
        timeout,
    )

    _element_exists = self._browser_evaluate(
        expression=commands.gen_window_element_exists_command(
            window_index=window,
            selector=selector,
            element_index=element_index,
            retry_interval=retry_interval,
            timeout=timeout,
        ),
    )

    self.logger.info(
        "element with selector '%s' #%s %s in window %s",
        selector,
        element_index,
        'exists' if _element_exists else 'does not exist',
        window,
    )

    return _element_exists

evaluate(expression, window=0)

Evaluates the given JavaScript expression in the given window and returns the result.

If window is set to None, the expression gets evaluated in the Milan frontend.

Source code in milan/browser.py
@browser_function
@frontend_function
def evaluate(self, expression, window=0):
    """
    Evaluates the given JavaScript expression in the given window and
    returns the result.

    If `window` is set to `None`, the expression gets evaluated in the
    Milan frontend.
    """

    # evaluate in the real browser
    if window is None:
        return self._browser_evaluate(
            expression=commands.gen_evaluate_command(
                expression=expression,
            ),
        )

    # evaluate in one of the windows
    return self._browser_evaluate(
        expression=commands.gen_window_evaluate_command(
            window_index=window,
            expression=expression,
        ),
    )

fill(selector, value, element_index=0, retry_interval=None, timeout=None, animation=None, window=0)

Waits for at least one input matching the given selector and fills the given value into it.

If animation is set to true, an animation using the cursor is played. If animation is set to None the Browser.animation property is used to determine if an animation should be played.

If element_index is set, a matching element with the given index is awaited and its attributes are used.

If retry_interval is set to None the Browser.selector_retry_interval property is used instead.

If timeout is set to None the Browser.selector_timeout property is used instead.

Source code in milan/browser.py
@frontend_function
@browser_function
def fill(
        self,
        selector,
        value,
        element_index=0,
        retry_interval=None,
        timeout=None,
        animation=None,
        window=0,
):

    """
    Waits for at least one input matching the given selector and fills the
    given value into it.

    If `animation` is set to true, an animation using the cursor is played.
    If animation is set to `None` the `Browser.animation` property is used
    to determine if an animation should be played.

    If `element_index` is set, a matching element with the given index
    is awaited and its attributes are used.

    If `retry_interval` is set to `None` the
    `Browser.selector_retry_interval` property is used instead.

    If `timeout` is set to `None` the
    `Browser.selector_timeout` property is used instead.
    """

    retry_interval = self._get_selector_retry_interval(retry_interval)
    timeout = self._get_selector_timeout(timeout)

    self.logger.info(
        "filling value '%s' #%s into an element with selector '%s' in window %s with a timeout of %ss",  # NOQA
        value,
        selector,
        element_index,
        window,
        timeout,
    )

    return self._browser_evaluate(
        expression=commands.gen_window_fill_command(
            window_index=window,
            selector=selector,
            element_index=element_index,
            value=value,
            retry_interval=retry_interval,
            timeout=timeout,
            animation=self._get_animations(animation),
        ),
    )

get_attribute(selector, name, element_index=0, retry_interval=None, timeout=None, window=0)

Waits for at least one element matching the given selector and returns the attribute with the given name.

If element_index is set, a matching element with the given index is awaited and its attributes are used.

If retry_interval is set to None the Browser.selector_retry_interval property is used instead.

If timeout is set to None the Browser.selector_timeout property is used instead.

Source code in milan/browser.py
@frontend_function
@browser_function
def get_attribute(
        self,
        selector,
        name,
        element_index=0,
        retry_interval=None,
        timeout=None,
        window=0,
):

    """
    Waits for at least one element matching the given selector and returns
    the attribute with the given name.

    If `element_index` is set, a matching element with the given index
    is awaited and its attributes are used.

    If `retry_interval` is set to `None` the
    `Browser.selector_retry_interval` property is used instead.

    If `timeout` is set to `None` the
    `Browser.selector_timeout` property is used instead.
    """

    retry_interval = self._get_selector_retry_interval(retry_interval)
    timeout = self._get_selector_timeout(timeout)

    self.logger.info(
        "getting attribute '%s' from element with selector '%s' #%s in window %s with a timeout of %ss",  # NOQA
        name,
        selector,
        element_index,
        window,
        timeout,
    )

    return self._browser_evaluate(
        expression=commands.gen_window_get_attribute_command(
            window_index=window,
            selector=selector,
            element_index=element_index,
            name=name,
            retry_interval=retry_interval,
            timeout=timeout,
        ),
    )

get_attributes(selector, element_index=0, retry_interval=None, timeout=None, window=0)

Waits for at least one element matching the given selector and returns all of its attributes as a dict.

If element_index is set, a matching element with the given index is awaited and its attributes are returned.

If retry_interval is set to None the Browser.selector_retry_interval property is used instead.

If timeout is set to None the Browser.selector_timeout property is used instead.

Source code in milan/browser.py
@frontend_function
@browser_function
def get_attributes(
        self,
        selector,
        element_index=0,
        retry_interval=None,
        timeout=None,
        window=0,
):

    """
    Waits for at least one element matching the given selector and returns
    all of its attributes as a dict.

    If `element_index` is set, a matching element with the given index
    is awaited and its attributes are returned.

    If `retry_interval` is set to `None` the
    `Browser.selector_retry_interval` property is used instead.

    If `timeout` is set to `None` the
    `Browser.selector_timeout` property is used instead.
    """

    retry_interval = self._get_selector_retry_interval(retry_interval)
    timeout = self._get_selector_timeout(timeout)

    self.logger.info(
        "getting attributes of element with selector '%s' #%s in window %s with a timeout of %ss",  # NOQA
        selector,
        element_index,
        window,
        timeout,
    )

    return self._browser_evaluate(
        expression=commands.gen_window_get_attributes_command(
            window_index=window,
            selector=selector,
            element_index=element_index,
            retry_interval=retry_interval,
            timeout=timeout,
        ),
    )

get_class_list(selector, element_index=0, retry_interval=None, timeout=None, window=0)

Waits for at least one element matching the given selector and returns its CSS class list as a list of strings.

If element_index is set, a matching element with the given index is awaited and its attributes are used.

If retry_interval is set to None the Browser.selector_retry_interval property is used instead.

If timeout is set to None the Browser.selector_timeout property is used instead.

Source code in milan/browser.py
def get_class_list(
        self,
        selector,
        element_index=0,
        retry_interval=None,
        timeout=None,
        window=0,
):

    """
    Waits for at least one element matching the given selector and returns
    its CSS class list as a list of strings.

    If `element_index` is set, a matching element with the given index
    is awaited and its attributes are used.

    If `retry_interval` is set to `None` the
    `Browser.selector_retry_interval` property is used instead.

    If `timeout` is set to `None` the
    `Browser.selector_timeout` property is used instead.
    """

    class_list = self.get_attribute(
        selector=selector,
        element_index=element_index,
        name='class',
        retry_interval=retry_interval,
        timeout=timeout,
        window=window,
    ).split(' ')

    return [i for i in class_list if i]

get_cursor_position()

Returns the cursor position as dict.

Example return value: {'x': 640, 'y': 360}

Source code in milan/browser.py
@frontend_function
@browser_function
def get_cursor_position(self):
    """
    Returns the cursor position as dict.

    Example return value: `{'x': 640, 'y': 360}`
    """

    return self._browser_evaluate(
        expression=commands.gen_cursor_get_position_command(),
    )

get_element_count(selector, window=0)

Returns the amount of elements matching the given selector in the given window as integer.

Source code in milan/browser.py
@frontend_function
@browser_function
def get_element_count(
        self,
        selector,
        window=0,
):

    """
    Returns the amount of elements matching the given selector in the
    given window as integer.
    """

    self.logger.info(
        "counting elements with selector '%s' in window %s",
        selector,
        window,
    )

    element_count = self._browser_evaluate(
        expression=commands.gen_window_get_element_count_command(
            window_index=window,
            selector=selector,
        ),
    )

    return element_count

get_fullscreen(window=0)

Returns whether fullscreen is enabled for the given window as bool.

Source code in milan/browser.py
@frontend_function
@browser_function
def get_fullscreen(self, window=0):
    """
    Returns whether fullscreen is enabled for the given window as bool.        
    """

    return self._browser_evaluate(
        expression=commands.gen_window_get_fullscreen_command(
            window_index=window,
        ),
    )

get_html(selector, element_index=0, retry_interval=None, timeout=None, window=0)

Waits for at least one element matching the given selector and returns its HTML as string.

If element_index is set, a matching element with the given index is awaited and its value is returned.

If retry_interval is set to None the Browser.selector_retry_interval property is used instead.

If timeout is set to None the Browser.selector_timeout property is used instead.

Source code in milan/browser.py
@frontend_function
@browser_function
def get_html(
        self,
        selector,
        element_index=0,
        retry_interval=None,
        timeout=None,
        window=0,
):

    """
    Waits for at least one element matching the given selector and returns
    its HTML as string.

    If `element_index` is set, a matching element with the given index
    is awaited and its value is returned.

    If `retry_interval` is set to `None` the
    `Browser.selector_retry_interval` property is used instead.

    If `timeout` is set to `None` the
    `Browser.selector_timeout` property is used instead.
    """

    retry_interval = self._get_selector_retry_interval(retry_interval)
    timeout = self._get_selector_timeout(timeout)

    self.logger.info(
        "getting HTML from element with selector '%s' #%s in window %s with a timeout of %ss",  # NOQA
        selector,
        element_index,
        window,
        timeout,
    )

    return self._browser_evaluate(
        expression=commands.gen_window_get_html_command(
            window_index=window,
            selector=selector,
            element_index=element_index,
            retry_interval=retry_interval,
            timeout=timeout,
        ),
    )

get_size()

Returns the size of browser as dict.

Example return value: {'height': 720, 'width': 1_280}

Source code in milan/browser.py
@frontend_function
@browser_function
def get_size(self):
    """
    Returns the size of browser as dict.

    Example return value: `{'height': 720, 'width': 1_280}`
    """

    return self._browser_evaluate(
        expression=commands.gen_window_manager_get_size_command(),
    )

get_text(selector, element_index=0, retry_interval=None, timeout=None, window=0)

Waits for at least one element matching the given selector and returns its text as string.

If element_index is set, a matching element with the given index is awaited and its value is returned.

If retry_interval is set to None the Browser.selector_retry_interval property is used instead.

If timeout is set to None the Browser.selector_timeout property is used instead.

Source code in milan/browser.py
@frontend_function
@browser_function
def get_text(
        self,
        selector,
        element_index=0,
        retry_interval=None,
        timeout=None,
        window=0,
):

    """
    Waits for at least one element matching the given selector and returns
    its text as string.

    If `element_index` is set, a matching element with the given index
    is awaited and its value is returned.

    If `retry_interval` is set to `None` the
    `Browser.selector_retry_interval` property is used instead.

    If `timeout` is set to `None` the
    `Browser.selector_timeout` property is used instead.
    """

    retry_interval = self._get_selector_retry_interval(retry_interval)
    timeout = self._get_selector_timeout(timeout)

    self.logger.info(
        "getting text from element with selector '%s' #%s in window %s with a timeout of %ss",  # NOQA
        selector,
        element_index,
        window,
        timeout,
    )

    return self._browser_evaluate(
        expression=commands.gen_window_get_text_command(
            window_index=window,
            selector=selector,
            element_index=element_index,
            retry_interval=retry_interval,
            timeout=timeout,
        ),
    )

get_url(window=0)

Returns the URL of the given window as a milan.utils.url.URL object.

Source code in milan/browser.py
def get_url(self, window=0):
    """
    Returns the URL of the given window as a `milan.utils.url.URL` object.
    """

    raw_url = self._get_url(window=window)

    return URL(raw_url)

get_window_count()

Returns the count of visible browser windows as integer.

Source code in milan/browser.py
@frontend_function
@browser_function
def get_window_count(self):
    """
    Returns the count of visible browser windows as integer.
    """

    return self._browser_evaluate(
        expression=commands.gen_window_manager_get_window_count_command(),
    )

get_window_size(window=0)

Returns the size of the given window.

Example return value: {'height': 720, 'width': 1_280}

Source code in milan/browser.py
@frontend_function
@browser_function
def get_window_size(self, window=0):
    """
    Returns the size of the given window.

    Example return value: `{'height': 720, 'width': 1_280}`
    """

    return self._browser_evaluate(
        expression=commands.gen_window_get_size_command(
            window_index=window,
        ),
    )

hide_cursor()

Hides cursor.

Has no effect if cursor is already visible.

Source code in milan/browser.py
@frontend_function
@browser_function
def hide_cursor(self):
    """
    Hides cursor.

    Has no effect if cursor is already visible.
    """

    self.logger.info('hiding cursor')

    return self._browser_evaluate(
        expression=commands.gen_cursor_hide_command(),
    )

highlight_elements(selectors, index=None, count=None, retry_interval=None, timeout=None, border_width=2, border_style='solid', border_color='#FF0000', padding=10, track=True, duration=None, window=0)

Waits for at least one element matching the given selector and selects and draws a marker around it.

If duration is set to a number, the method will block for the given duration and the highlights will be removed afterwards.

If track is set to true, the marker will track possible movements of the highlighted element.

If element_index is set, a matching element with the given index is awaited and its attributes are used.

If retry_interval is set to None the Browser.selector_retry_interval property is used instead.

If timeout is set to None the Browser.selector_timeout property is used instead.

Source code in milan/browser.py
@browser_function
@frontend_function
def highlight_elements(
    self,
    selectors,
    index=None,
    count=None,
    retry_interval=None,
    timeout=None,
    border_width=2,
    border_style='solid',
    border_color='#FF0000',
    padding=10,
    track=True,
    duration=None,
    window=0,
):

    """
    Waits for at least one element matching the given selector and
    selects and draws a marker around it.

    If `duration` is set to a number, the method will block for the given
    duration and the highlights will be removed afterwards.

    If `track` is set to true, the marker will track possible movements
    of the highlighted element.

    If `element_index` is set, a matching element with the given index
    is awaited and its attributes are used.

    If `retry_interval` is set to `None` the
    `Browser.selector_retry_interval` property is used instead.

    If `timeout` is set to `None` the
    `Browser.selector_timeout` property is used instead.
    """

    retry_interval = self._get_selector_retry_interval(retry_interval)
    timeout = self._get_selector_timeout(timeout)

    if not isinstance(selectors, (list, tuple)):
        selectors = [selectors]

    return self._browser_evaluate(
        expression=commands.gen_window_highlight_elements_command(
            window_index=window,
            selectors=selectors,
            index=index,
            count=count,
            retry_interval=retry_interval,
            timeout=timeout,
            border_width=border_width,
            border_style=border_style,
            border_color=border_color,
            padding=padding,
            track=track,
            duration=duration,
        ),
    )

move_cursor(x=0, y=0, animation=None)

Moves cursor to given X and Y coordinates.

If animation is set to true, the cursor is animated. If animation is set to None the Browser.animation property is used to determine if an animation should be played.

Source code in milan/browser.py
@frontend_function
@browser_function
def move_cursor(
        self,
        x=0,
        y=0,
        animation=None,
):

    """
    Moves cursor to given X and Y coordinates.

    If `animation` is set to true, the cursor is animated. If animation is
    set to `None` the `Browser.animation` property is used to determine if
    an animation should be played.
    """

    self.logger.info('moving cursor to x=%s y=%s', x, y)

    return self._browser_evaluate(
        expression=commands.gen_cursor_move_to_command(
            x=float(x),
            y=float(y),
            animation=self._get_animations(animation),
        ),
    )

move_cursor_to_home(animation=None)

Moves cursor to the middle of the screen.

If animation is set to true, the cursor is animated. If animation is set to None the Browser.animation property is used to determine if an animation should be played.

Source code in milan/browser.py
@frontend_function
@browser_function
def move_cursor_to_home(self, animation=None):
    """
    Moves cursor to the middle of the screen.

    If `animation` is set to true, the cursor is animated. If animation is
    set to `None` the `Browser.animation` property is used to determine if
    an animation should be played.
    """

    self.logger.info('moving cursor to home')

    return self._browser_evaluate(
        expression=commands.gen_cursor_move_to_home_command(
            animation=self._get_animations(animation),
        ),
    )

navigate(url, window=0, animation=None)

Navigates the given window to the given URL.

If animation is set to true, an animation is played that uses the cursor to click and fill the address bar of the window.

If animation is set to None the Browser.animation property is used to determine if an animation should be played.

Source code in milan/browser.py
@browser_function
@frontend_function
def navigate(self, url, window=0, animation=None):
    """
    Navigates the given window to the given URL.

    If `animation` is set to true, an animation is played that uses the
    cursor to click and fill the address bar of the window.

    If `animation` is set to `None` the `Browser.animation` property is
    used to determine if an animation should be played.
    """

    # TODO: add support for external sites besides 'localhost'
    # TODO: add support for cursor bootstrapping

    url = URL(url)

    # rewrite 'localhost' to '127.0.0.1' to prevent cookie settings loops
    # between the two origins (the frontend runs on '127.0.0.1')
    if url.host == 'localhost':
        url.host = '127.0.0.1'

    self.logger.info('navigating frontend to %s', url)

    return self._browser_evaluate(
        expression=commands.gen_window_navigate_command(
            window_index=window,
            url=str(url),
            animation=self._get_animations(animation),
        ),
    )

navigate_back(window=0, animation=None)

Moves back in the history of the given window.

If animation is set to true, an animation is played that uses the cursor to click on the back button of the given window.

If animation is set to None the Browser.animation property is used to determine if an animation should be played.

Source code in milan/browser.py
@frontend_function
@browser_function
def navigate_back(self, window=0, animation=None):
    """
    Moves back in the history of the given window.

    If `animation` is set to true, an animation is played that uses the
    cursor to click on the back button of the given window.

    If `animation` is set to `None` the `Browser.animation` property is
    used to determine if an animation should be played.
    """

    self.logger.info('navigating window %s back', window)

    return self._browser_evaluate(
        expression=commands.gen_window_navigate_back_command(
            window_index=window,
            animation=self._get_animations(animation),
        ),
    )

navigate_forward(window=0, animation=None)

Moves forward in the history of the given window.

If animation is set to true, an animation is played that uses the cursor to click on the forward button of the given window.

If animation is set to None the Browser.animation property is used to determine if an animation should be played.

Source code in milan/browser.py
@frontend_function
@browser_function
def navigate_forward(self, window=0, animation=None):
    """
    Moves forward in the history of the given window.

    If `animation` is set to true, an animation is played that uses the
    cursor to click on the forward button of the given window.

    If `animation` is set to `None` the `Browser.animation` property is
    used to determine if an animation should be played.
    """

    self.logger.info('navigating window %s forward', window)

    return self._browser_evaluate(
        expression=commands.gen_window_navigate_forward_command(
            window_index=window,
            animation=self._get_animations(animation),
        ),
    )

navigate_to_test_application(*args, **kwargs)

Navigates the given window to the Milan test application.

Source code in milan/browser.py
def navigate_to_test_application(self, *args, **kwargs):
    """
    Navigates the given window to the Milan test application.
    """

    return self.navigate(
        url=self._frontend_server.get_test_application_url(),
        *args,
        **kwargs,
    )

reload(window=0, animation=None)

Reloads the given window.

If animation is set to true, an animation is played that uses the cursor to click on the reload button of the given window.

If animation is set to None the Browser.animation property is used to determine if an animation should be played.

Source code in milan/browser.py
@frontend_function
@browser_function
def reload(self, window=0, animation=None):
    """
    Reloads the given window.

    If `animation` is set to true, an animation is played that uses the
    cursor to click on the reload button of the given window.

    If `animation` is set to `None` the `Browser.animation` property is
    used to determine if an animation should be played.
    """

    self.logger.info('reloading window %s', window)

    return self._browser_evaluate(
        expression=commands.gen_window_reload_command(
            window_index=window,
            animation=self._get_animations(animation),
        ),
    )

reload_frontend()

Reloads the Milan frontend.

Source code in milan/browser.py
@browser_function
def reload_frontend(self):
    """
    Reloads the Milan frontend.
    """

    self.logger.info('loading frontend')

    self._browser_navigate(url=self._frontend_server.get_frontend_url())

remove_attribute(selector, name, element_index=0, retry_interval=None, timeout=None, window=0)

Waits for at least one element matching the given selector and removes the given attribute name.

If element_index is set, a matching element with the given index is awaited and its attributes are used.

If retry_interval is set to None the Browser.selector_retry_interval property is used instead.

If timeout is set to None the Browser.selector_timeout property is used instead.

Source code in milan/browser.py
def remove_attribute(
        self,
        selector,
        name,
        element_index=0,
        retry_interval=None,
        timeout=None,
        window=0,
):

    """
    Waits for at least one element matching the given selector and removes
    the given attribute name.

    If `element_index` is set, a matching element with the given index
    is awaited and its attributes are used.

    If `retry_interval` is set to `None` the
    `Browser.selector_retry_interval` property is used instead.

    If `timeout` is set to `None` the
    `Browser.selector_timeout` property is used instead.
    """

    return self.remove_attributes(
        selector=selector,
        names=[name],
        element_index=element_index,
        retry_interval=retry_interval,
        timeout=timeout,
        window=window,
    )

remove_attributes(selector, names, element_index=0, retry_interval=None, timeout=None, window=0)

Waits for at least one element matching the given selector and removes the given attribute names.

If element_index is set, a matching element with the given index is awaited and its attributes are used.

If retry_interval is set to None the Browser.selector_retry_interval property is used instead.

If timeout is set to None the Browser.selector_timeout property is used instead.

Source code in milan/browser.py
@frontend_function
@browser_function
def remove_attributes(
        self,
        selector,
        names,
        element_index=0,
        retry_interval=None,
        timeout=None,
        window=0,
):

    """
    Waits for at least one element matching the given selector and removes
    the given attribute names.

    If `element_index` is set, a matching element with the given index
    is awaited and its attributes are used.

    If `retry_interval` is set to `None` the
    `Browser.selector_retry_interval` property is used instead.

    If `timeout` is set to `None` the
    `Browser.selector_timeout` property is used instead.
    """

    retry_interval = self._get_selector_retry_interval(retry_interval)
    timeout = self._get_selector_timeout(timeout)

    self.logger.info(
        "removing attributes '%s' of element with selector '%s' #%s in window %s with a timeout of %ss",  # NOQA
        names,
        selector,
        element_index,
        window,
        timeout,
    )

    return self._browser_evaluate(
        expression=commands.gen_window_remove_attributes_command(
            window_index=window,
            selector=selector,
            element_index=element_index,
            names=names,
            retry_interval=retry_interval,
            timeout=timeout,
        ),
    )

remove_highlights(window=0)

Removes all highlight markers in the given window.

Source code in milan/browser.py
@browser_function
@frontend_function
def remove_highlights(self, window=0):
    """
    Removes all highlight markers in the given window.
    """

    return self._browser_evaluate(
        expression=commands.gen_window_remove_highlights_command(
            window_index=window,
        ),
    )

screenshot(path)

Writes a screenshot of the current page to the given path.

Source code in milan/browser.py
@browser_function
def screenshot(self, path):
    """
    Writes a screenshot of the current page to the given path.
    """

    raise NotImplementedError()

select(selector, element_index=0, value=None, index=None, label=None, retry_interval=None, timeout=None, window=0, animation=None)

Waits for at least one select element matching the given selector and selects an option specified by value, index, or label.

If animation is set to true, an animation using the cursor is played. If animation is set to None the Browser.animation property is used to determine if an animation should be played.

If element_index is set, a matching element with the given index is awaited and its attributes are used.

If retry_interval is set to None the Browser.selector_retry_interval property is used instead.

If timeout is set to None the Browser.selector_timeout property is used instead.

Source code in milan/browser.py
@frontend_function
@browser_function
def select(
        self,
        selector,
        element_index=0,
        value=None,
        index=None,
        label=None,
        retry_interval=None,
        timeout=None,
        window=0,
        animation=None,
):

    """
    Waits for at least one select element matching the given selector and
    selects an option specified by `value`, `index`, or `label`.

    If `animation` is set to true, an animation using the cursor is played.
    If animation is set to `None` the `Browser.animation` property is used
    to determine if an animation should be played.

    If `element_index` is set, a matching element with the given index
    is awaited and its attributes are used.

    If `retry_interval` is set to `None` the
    `Browser.selector_retry_interval` property is used instead.

    If `timeout` is set to `None` the
    `Browser.selector_timeout` property is used instead.
    """

    retry_interval = self._get_selector_retry_interval(retry_interval)
    timeout = self._get_selector_timeout(timeout)

    identifier = ''

    if value:
        identifier = f"value '{value}'"

    elif value:
        identifier = f"index '{index}'"

    elif label:
        identifier = f"label '{label}'"

    self.logger.info(
        "selecting option with %s in select with selector '%s' #%s in window %s with a timeout of %ss",  # NOQA
        identifier,
        selector,
        element_index,
        window,
        timeout,
    )

    return self._browser_evaluate(
        expression=commands.gen_window_select_command(
            window_index=window,
            selector=selector,
            element_index=element_index,
            value=value,
            index=index,
            label=label,
            retry_interval=retry_interval,
            timeout=timeout,
            animation=self._get_animations(animation),
        ),
    )

set_attribute(selector, name, value, element_index=0, retry_interval=None, timeout=None, window=0)

Waits for at least one element matching the given selector and sets the given attribute name to the given value.

If element_index is set, a matching element with the given index is awaited and its attributes are used.

If retry_interval is set to None the Browser.selector_retry_interval property is used instead.

If timeout is set to None the Browser.selector_timeout property is used instead.

Source code in milan/browser.py
def set_attribute(
        self,
        selector,
        name,
        value,
        element_index=0,
        retry_interval=None,
        timeout=None,
        window=0,
):

    """
    Waits for at least one element matching the given selector and sets
    the given attribute name to the given value.

    If `element_index` is set, a matching element with the given index
    is awaited and its attributes are used.

    If `retry_interval` is set to `None` the
    `Browser.selector_retry_interval` property is used instead.

    If `timeout` is set to `None` the
    `Browser.selector_timeout` property is used instead.
    """

    return self.set_attributes(
        selector=selector,
        element_index=element_index,
        attributes={name: value},
        retry_interval=retry_interval,
        timeout=timeout,
        window=window,
    )

set_attributes(selector, attributes, element_index=0, retry_interval=None, timeout=None, window=0)

Waits for at least one element matching the given selector and sets the given attributes provided as a dict.

If element_index is set, a matching element with the given index is awaited and its attributes are set.

If retry_interval is set to None the Browser.selector_retry_interval property is used instead.

If timeout is set to None the Browser.selector_timeout property is used instead.

Source code in milan/browser.py
@frontend_function
@browser_function
def set_attributes(
        self,
        selector,
        attributes,
        element_index=0,
        retry_interval=None,
        timeout=None,
        window=0,
):

    """
    Waits for at least one element matching the given selector and sets
    the given attributes provided as a dict.

    If `element_index` is set, a matching element with the given index
    is awaited and its attributes are set.

    If `retry_interval` is set to `None` the
    `Browser.selector_retry_interval` property is used instead.

    If `timeout` is set to `None` the
    `Browser.selector_timeout` property is used instead.
    """

    retry_interval = self._get_selector_retry_interval(retry_interval)
    timeout = self._get_selector_timeout(timeout)

    self.logger.info(
        "setting attributes of element with selector '%s' #%s in window %s with a timeout of %ss",  # NOQA
        selector,
        element_index,
        window,
        timeout,
    )

    return self._browser_evaluate(
        expression=commands.gen_window_set_attributes_command(
            window_index=window,
            selector=selector,
            element_index=element_index,
            attributes=attributes,
            retry_interval=retry_interval,
            timeout=timeout,
        ),
    )

set_background(background)

Sets the background as CSS property.

Example values
  • red
  • #FF0000
  • linear-gradient(0deg, rgba(34,193,195,1) 0%, rgba(253,187,45,1) 100%)
Source code in milan/browser.py
@frontend_function
@browser_function
def set_background(self, background):
    """
    Sets the background as CSS property.

    Example values:
      - `red`
      - `#FF0000`
      - `linear-gradient(0deg, rgba(34,193,195,1) 0%, rgba(253,187,45,1) 100%)`
    """

    return self._browser_evaluate(
        expression=commands.gen_window_manager_set_background_command(
            background=background,
        ),
    )

set_background_url(url)

Sets the URL of the frontends background IFrame.

Default is /_milan/frontend/background/index.html

Source code in milan/browser.py
@frontend_function
@browser_function
def set_background_url(self, url):
    """
    Sets the URL of the frontends background IFrame.

    Default is `/_milan/frontend/background/index.html`
    """

    return self._browser_evaluate(
        expression=commands.gen_window_manager_set_background_url_command(
            url=url,
        ),
    )

set_class_list(selector, names, element_index=0, retry_interval=None, timeout=None, window=0)

Waits for at least one element matching the given selector and sets its CSS class list to the given list of strings.

If element_index is set, a matching element with the given index is awaited and its attributes are used.

If retry_interval is set to None the Browser.selector_retry_interval property is used instead.

If timeout is set to None the Browser.selector_timeout property is used instead.

Source code in milan/browser.py
def set_class_list(
        self,
        selector,
        names,
        element_index=0,
        retry_interval=None,
        timeout=None,
        window=0,
):

    """
    Waits for at least one element matching the given selector and sets
    its CSS class list to the given list of strings.

    If `element_index` is set, a matching element with the given index
    is awaited and its attributes are used.

    If `retry_interval` is set to `None` the
    `Browser.selector_retry_interval` property is used instead.

    If `timeout` is set to `None` the
    `Browser.selector_timeout` property is used instead.
    """

    return self.set_attribute(
        selector=selector,
        name='class',
        value=' '.join(names),
        element_index=element_index,
        retry_interval=retry_interval,
        timeout=timeout,
        window=window,
    )

set_color_scheme(color_scheme)

Sets the color scheme of the browser.

Possible values
  • light
  • dark
Source code in milan/browser.py
def set_color_scheme(self, color_scheme):
    """
    Sets the color scheme of the browser.

    Possible values:
      - light
      - dark
    """

    raise NotImplementedError()

set_fullscreen(window=0, fullscreen=True, decorations=True)

Enables or disables fullscreen mode for the given window.

If decorations is set to False, the window decorations are not shown and the page is in "true" fullscreen mode.

Source code in milan/browser.py
@frontend_function
@browser_function
def set_fullscreen(self, window=0, fullscreen=True, decorations=True):
    """
    Enables or disables fullscreen mode for the given window.

    If decorations is set to `False`, the window decorations are not shown
    and the page is in "true" fullscreen mode.
    """

    self.logger.info(
        '%s fullscreen for window %s %s decorations',
        'enabling' if fullscreen else 'disabling',
        window,
        'with' if decorations else 'without',
    )

    return self._browser_evaluate(
        expression=commands.gen_window_set_fullscreen_command(
            window_index=window,
            fullscreen=fullscreen,
            decorations=decorations,
        ),
    )

set_html(selector, html, element_index=0, retry_interval=None, timeout=None, window=0)

Waits for at least one element matching the given selector and sets its HTML to the given string.

If element_index is set, a matching element with the given index is awaited and its HTML is set.

If retry_interval is set to None the Browser.selector_retry_interval property is used instead.

If timeout is set to None the Browser.selector_timeout property is used instead.

Source code in milan/browser.py
@frontend_function
@browser_function
def set_html(
        self,
        selector,
        html,
        element_index=0,
        retry_interval=None,
        timeout=None,
        window=0,
):

    """
    Waits for at least one element matching the given selector and sets
    its HTML to the given string.

    If `element_index` is set, a matching element with the given index
    is awaited and its HTML is set.

    If `retry_interval` is set to `None` the
    `Browser.selector_retry_interval` property is used instead.

    If `timeout` is set to `None` the
    `Browser.selector_timeout` property is used instead.
    """

    retry_interval = self._get_selector_retry_interval(retry_interval)
    timeout = self._get_selector_timeout(timeout)

    self.logger.info(
        "setting HTML in element with selector '%s' #%s in window %s with a timeout of %ss",  # NOQA
        selector,
        element_index,
        window,
        timeout,
    )

    return self._browser_evaluate(
        expression=commands.gen_window_set_html_command(
            window_index=window,
            selector=selector,
            element_index=element_index,
            html=html,
            retry_interval=retry_interval,
            timeout=timeout,
        ),
    )

set_size(width=0, height=0, even_values=True)

Resizes the browser to the given width and height.

If even_values is set to true, odd values get rounded to even numbers. This is necessary for some FFmpeg filters.

Source code in milan/browser.py
@browser_function
def set_size(self, width=0, height=0, even_values=True):
    """
    Resizes the browser to the given width and height.

    If `even_values` is set to true, odd values get rounded to even
    numbers. This is necessary for some FFmpeg filters.
    """

    if even_values:
        width = width + (width % 2)
        height = height + (height % 2)

    return self._browser_set_size(
        width=width,
        height=height,
    )

set_text(selector, text, element_index=0, retry_interval=None, timeout=None, window=0)

Waits for at least one element matching the given selector and sets its text to the given string.

If element_index is set, a matching element with the given index is awaited and its text is set.

If retry_interval is set to None the Browser.selector_retry_interval property is used instead.

If timeout is set to None the Browser.selector_timeout property is used instead.

Source code in milan/browser.py
def set_text(
        self,
        selector,
        text,
        element_index=0,
        retry_interval=None,
        timeout=None,
        window=0,
):

    """
    Waits for at least one element matching the given selector and sets
    its text to the given string.

    If `element_index` is set, a matching element with the given index
    is awaited and its text is set.

    If `retry_interval` is set to `None` the
    `Browser.selector_retry_interval` property is used instead.

    If `timeout` is set to `None` the
    `Browser.selector_timeout` property is used instead.
    """

    return self.set_html(
        selector=selector,
        html=text,
        element_index=element_index,
        retry_interval=retry_interval,
        timeout=timeout,
        window=window,
    )

set_watermark(text)

Sets the watermark of the frontends background.

Default is f'Milan v{milan.VERSION_STRING}'

Source code in milan/browser.py
@frontend_function
@browser_function
def set_watermark(self, text):
    """
    Sets the watermark of the frontends background.

    Default is `f'Milan v{milan.VERSION_STRING}'`
    """

    return self._browser_evaluate(
        expression=commands.gen_window_manager_set_watermark_command(
            text=text,
        ),
    )

set_window_size(width, height, window=0, even_values=True)

Sets the size of the given window.

If even_values is set to true, odd values get rounded to even numbers. This is necessary for some FFmpeg filters.

Source code in milan/browser.py
def set_window_size(self, width, height, window=0, even_values=True):
    """
    Sets the size of the given window.

    If `even_values` is set to true, odd values get rounded to even
    numbers. This is necessary for some FFmpeg filters.
    """

    current_browser_size = self.get_size()
    current_window_size = self.get_window_size()

    width = width + (
        current_browser_size['width'] - current_window_size['width'])

    height = height + (
        current_browser_size['height'] - current_window_size['height'])

    return self.set_size(
        width=width,
        height=height,
        even_values=even_values,
    )

show_cursor()

Shows cursor.

Has no effect if cursor is already visible.

Source code in milan/browser.py
@frontend_function
@browser_function
def show_cursor(self):
    """
    Shows cursor.

    Has no effect if cursor is already visible.
    """

    self.logger.info('showing cursor')

    return self._browser_evaluate(
        expression=commands.gen_cursor_show_command(),
    )

split()

Split the frontend clockwise into multiple windows.

Max splits are three. So you can have four windows tops.

Source code in milan/browser.py
@frontend_function
@browser_function
def split(self):
    """
    Split the frontend clockwise into multiple windows.

    Max splits are three. So you can have four windows tops.
    """

    self.logger.info('splitting window')

    return self._browser_evaluate(
        expression=commands.gen_window_manager_split_command(),
    )

start_video_capturing(path, delay=DEFAULT_VIDEO_CAPTURING_START_DELAY)

Starts video capturing into the given path.

The video format is determined by the file extension of the given path.

Possible video formats
  • webm
  • mp4
  • gif
Source code in milan/browser.py
@browser_function
def start_video_capturing(
        self,
        path,
        delay=DEFAULT_VIDEO_CAPTURING_START_DELAY,
):

    """
    Starts video capturing into the given path.

    The video format is determined by the file extension of the given
    path.

    Possible video formats:
      - webm
      - mp4
      - gif
    """

    raise NotImplementedError()

stop()

Stops the browser.

When video capturing is still running, Browser.stop_video_capturing is called automatically.

Source code in milan/browser.py
def stop(self):
    """
    Stops the browser.

    When video capturing is still running, `Browser.stop_video_capturing`
    is called automatically.
    """

    raise NotImplementedError()