|
22 | 22 | import org.junit.Test; |
23 | 23 | import org.junit.runner.RunWith; |
24 | 24 | import org.openqa.selenium.By; |
| 25 | +import org.openqa.selenium.InvalidSelectorException; |
25 | 26 | import org.openqa.selenium.WebDriver; |
26 | 27 | import org.openqa.selenium.WebElement; |
27 | 28 | import org.openqa.selenium.htmlunit.WebDriverTestCase; |
@@ -104,4 +105,109 @@ public void relativeElementsByXPath() throws Exception { |
104 | 105 | assertEquals(1, elements.size()); |
105 | 106 | assertEquals("testId2", elements.get(0).getAttribute("id")); |
106 | 107 | } |
| 108 | + |
| 109 | + @Test(expected = InvalidSelectorException.class) |
| 110 | + public void elementsByXPathEmpty() throws Exception { |
| 111 | + final String html = "<html>\n" |
| 112 | + + "<head>\n" |
| 113 | + + "</head>\n" |
| 114 | + + "<body>\n" |
| 115 | + + " <div id='ctx'>\n" |
| 116 | + + " <div id='testId' class='other'></div>\n" |
| 117 | + + " <div id='testId2' class='testClass'></div>\n" |
| 118 | + + " </div>\n" |
| 119 | + + "</body>\n" |
| 120 | + + "</html>\n"; |
| 121 | + |
| 122 | + final WebDriver driver = loadPage2(html); |
| 123 | + final WebElement ctx = driver.findElement(By.id("ctx")); |
| 124 | + ctx.findElements(By.xpath("")); |
| 125 | + } |
| 126 | + |
| 127 | + @Test(expected = IllegalArgumentException.class) |
| 128 | + public void elementsByXPathNull() throws Exception { |
| 129 | + final String html = "<html>\n" |
| 130 | + + "<head>\n" |
| 131 | + + "</head>\n" |
| 132 | + + "<body>\n" |
| 133 | + + " <div id='ctx'>\n" |
| 134 | + + " <div id='testId' class='other'></div>\n" |
| 135 | + + " <div id='testId2' class='testClass'></div>\n" |
| 136 | + + " </div>\n" |
| 137 | + + "</body>\n" |
| 138 | + + "</html>\n"; |
| 139 | + |
| 140 | + final WebDriver driver = loadPage2(html); |
| 141 | + final WebElement ctx = driver.findElement(By.id("ctx")); |
| 142 | + ctx.findElements(By.xpath(null)); |
| 143 | + } |
| 144 | + |
| 145 | + @Test(expected = InvalidSelectorException.class) |
| 146 | + public void elementsByXPathBlank() throws Exception { |
| 147 | + final String html = "<html>\n" |
| 148 | + + "<head>\n" |
| 149 | + + "</head>\n" |
| 150 | + + "<body>\n" |
| 151 | + + " <div id='ctx'>\n" |
| 152 | + + " <div id='testId' class='other'></div>\n" |
| 153 | + + " <div id='testId2' class='testClass'></div>\n" |
| 154 | + + " </div>\n" |
| 155 | + + "</body>\n" |
| 156 | + + "</html>\n"; |
| 157 | + |
| 158 | + final WebDriver driver = loadPage2(html); |
| 159 | + final WebElement ctx = driver.findElement(By.id("ctx")); |
| 160 | + ctx.findElements(By.xpath(" \t ")); |
| 161 | + } |
| 162 | + |
| 163 | + @Test(expected = InvalidSelectorException.class) |
| 164 | + public void elementByXPathEmpty() throws Exception { |
| 165 | + final String html = "<html>\n" |
| 166 | + + "<head>\n" |
| 167 | + + "</head>\n" |
| 168 | + + "<body>\n" |
| 169 | + + " <div id='ctx'>\n" |
| 170 | + + " <div id='testId' class='other'></div>\n" |
| 171 | + + " <div id='testId2' class='testClass'></div>\n" |
| 172 | + + " </div>\n" |
| 173 | + + "</body>\n" |
| 174 | + + "</html>\n"; |
| 175 | + |
| 176 | + final WebDriver driver = loadPage2(html); |
| 177 | + driver.findElement(By.xpath("")); |
| 178 | + } |
| 179 | + |
| 180 | + @Test(expected = IllegalArgumentException.class) |
| 181 | + public void elementByXPathNull() throws Exception { |
| 182 | + final String html = "<html>\n" |
| 183 | + + "<head>\n" |
| 184 | + + "</head>\n" |
| 185 | + + "<body>\n" |
| 186 | + + " <div id='ctx'>\n" |
| 187 | + + " <div id='testId' class='other'></div>\n" |
| 188 | + + " <div id='testId2' class='testClass'></div>\n" |
| 189 | + + " </div>\n" |
| 190 | + + "</body>\n" |
| 191 | + + "</html>\n"; |
| 192 | + |
| 193 | + final WebDriver driver = loadPage2(html); |
| 194 | + driver.findElement(By.xpath(null)); |
| 195 | + } |
| 196 | + |
| 197 | + @Test(expected = InvalidSelectorException.class) |
| 198 | + public void elementByXPathBlank() throws Exception { |
| 199 | + final String html = "<html>\n" |
| 200 | + + "<head>\n" |
| 201 | + + "</head>\n" |
| 202 | + + "<body>\n" |
| 203 | + + " <div id='ctx'>\n" |
| 204 | + + " <div id='testId' class='other'></div>\n" |
| 205 | + + " <div id='testId2' class='testClass'></div>\n" |
| 206 | + + " </div>\n" |
| 207 | + + "</body>\n" |
| 208 | + + "</html>\n"; |
| 209 | + |
| 210 | + final WebDriver driver = loadPage2(html); |
| 211 | + driver.findElement(By.xpath(" \t ")); |
| 212 | + } |
107 | 213 | } |
0 commit comments