@@ -1727,4 +1727,90 @@ public void inputHiddenAdded() throws Exception {
17271727 final String url = getMockWebConnection ().getLastWebRequest ().getUrl ().toExternalForm ();
17281728 assertTrue (url .endsWith (getExpectedAlerts ()[0 ]));
17291729 }
1730+
1731+ /**
1732+ * @throws Exception if the test page can't be loaded
1733+ */
1734+ @ Test
1735+ @ Alerts ({"2" , "inp" , "submitButton" })
1736+ public void elements () throws Exception {
1737+ final String html
1738+ = "<html><head>\n "
1739+ + "<script>\n "
1740+ + LOG_TITLE_FUNCTION
1741+ + " function test() {\n "
1742+ + " log(document.forms[0].elements.length);\n "
1743+ + " log(document.forms[0].elements[0].id);\n "
1744+ + " log(document.forms[0].elements[1].id);\n "
1745+ + " }\n "
1746+ + "</script>\n "
1747+ + "</head>\n "
1748+ + "<body onload='test()'>\n "
1749+ + "<form id='form1' method='get' action='foo'>\n "
1750+ + " <input name='field1' value='val1' id='inp'/>\n "
1751+ + " <input type='submit' id='submitButton'/>\n "
1752+ + "</form>\n "
1753+ + "</body></html>" ;
1754+
1755+ loadPageVerifyTitle2 (html );
1756+ }
1757+
1758+ /**
1759+ * @throws Exception if the test page can't be loaded
1760+ */
1761+ @ Test
1762+ @ Alerts ({"1" , "[object HTMLInputElement]" })
1763+ public void elementsDetached () throws Exception {
1764+ final String html
1765+ = "<html><head>\n "
1766+ + "<script>\n "
1767+ + LOG_TITLE_FUNCTION
1768+ + " function test() {\n "
1769+ + " let frm = document.createElement('form');\n "
1770+ + " frm.appendChild(document.createElement('input'));\n "
1771+ + " frm.remove();\n "
1772+ + " log(frm.elements.length);\n "
1773+ + " log(frm.elements[0]);\n "
1774+ + " }\n "
1775+ + "</script>\n "
1776+ + "</head>\n "
1777+ + "<body onload='test()'>\n "
1778+ + "</body></html>" ;
1779+
1780+ loadPageVerifyTitle2 (html );
1781+ }
1782+
1783+ /**
1784+ * @throws Exception if the test page can't be loaded
1785+ */
1786+ @ Test
1787+ @ Alerts ({"2" , "inpt1" , "inpt2" , "1" , "inpt1" })
1788+ public void elementsDetachedFormAttribute () throws Exception {
1789+ final String html
1790+ = "<html><head>\n "
1791+ + "<script>\n "
1792+ + LOG_TITLE_FUNCTION
1793+ + " function test() {\n "
1794+ + " let frm = document.getElementById('formId');\n "
1795+
1796+ + " log(frm.elements.length);\n "
1797+ + " log(frm.elements[0].id);\n "
1798+ + " log(frm.elements[1].id);\n "
1799+
1800+ + " frm.remove();\n "
1801+ + " log(frm.elements.length);\n "
1802+ + " log(frm.elements[0].id);\n "
1803+ + " }\n "
1804+ + "</script>\n "
1805+ + "</head>\n "
1806+ + "<body onload='test()'>\n "
1807+ + " <form id='formId'>\n "
1808+ + " <input id='inpt1' type='text' name='textParam' value='textValue'>\n "
1809+ + " </form>\n "
1810+
1811+ + " <input form='formId' id='inpt2' type='text' name='textParam' value='textValue'>\n "
1812+ + "</body></html>" ;
1813+
1814+ loadPageVerifyTitle2 (html );
1815+ }
17301816}
0 commit comments