|
5 | 5 | import org.openqa.selenium.JavascriptExecutor;
|
6 | 6 | import org.openqa.selenium.NoSuchElementException;
|
7 | 7 | import org.openqa.selenium.WebElement;
|
| 8 | +import org.openqa.selenium.interactions.Actions; |
8 | 9 | import org.openqa.selenium.remote.RemoteWebDriver;
|
9 | 10 |
|
10 | 11 | import com.solvent.Solvent;
|
@@ -224,4 +225,69 @@ public boolean isElementPresentAndVisible(String locator, int wait) {
|
224 | 225 | }
|
225 | 226 | return present;
|
226 | 227 | }
|
| 228 | + |
| 229 | + public boolean isElementPresent(String locator) { |
| 230 | + return isElementPresent(locator, 5000); // could use properties file to set this value |
| 231 | + } |
| 232 | + |
| 233 | + public void moveTo(WebElement element) { |
| 234 | + Actions action = new Actions(driver); |
| 235 | + action.moveToElement(element).build().perform(); |
| 236 | + pause(500); |
| 237 | + } |
| 238 | + |
| 239 | + public void mouseOver(WebElement element) { |
| 240 | + StringBuilder sb = new StringBuilder(); |
| 241 | + sb.append("var element = arguments[0]"); |
| 242 | + sb.append("if (document.createEvent) {"); |
| 243 | + sb.append("var event = document.createEvent(\"MouseEvents\");"); |
| 244 | + sb.append("event.initMouseEvent(\"mouseover\", true, true, window, 0, 0," + |
| 245 | + "0, 0, 0, false, false, false, false, 0, null);"); |
| 246 | + sb.append("element.dispatchEvent(event);"); |
| 247 | + sb.append("}"); |
| 248 | + sb.append("else if (element.fireEvent) {"); |
| 249 | + sb.append("element.fireEvent(\"onmouseover\");"); |
| 250 | + sb.append("}"); |
| 251 | + driver.executeScript(sb.toString(), element); |
| 252 | + } |
| 253 | + |
| 254 | + public void mouseOver(String locator) { |
| 255 | + mouseOver(getElementUsingXpath(locator)); |
| 256 | + pause(500); |
| 257 | + } |
| 258 | + |
| 259 | + public void pause(long time) { |
| 260 | + SetMetWebDriverSession.pause(time); |
| 261 | + } |
| 262 | + |
| 263 | + public static void waitForContent() { |
| 264 | + log.debug("Wait for page content to be ready. Ensure all " + |
| 265 | + "ajax calls are complete before test continue."); |
| 266 | + SetMetWebDriverSession.pause(3000); // a simple way to wait for ajax |
| 267 | + } |
| 268 | + |
| 269 | + public void setCheckBox(WebElement checkbox, boolean check) { |
| 270 | + if (checkbox.isSelected()) { |
| 271 | + if (!check) { |
| 272 | + checkbox.click(); |
| 273 | + } |
274 | + } else if (check) { |
| 275 | + checkbox.click(); |
| 276 | + } |
| 277 | + } |
| 278 | + |
| 279 | + protected void setRadioByValue(List<WebElement> options, String value) { |
| 280 | + for (WebElement option:options) { |
| 281 | + String optionValue = option.getAttribute("value"); |
| 282 | + if (optionValue.hashCode() == value.hashCode()) { |
| 283 | + log.debug("\n found radio box with value='" + value + "'"); |
| 284 | + option.click(); |
| 285 | + break; |
| 286 | + } |
| 287 | + } |
| 288 | + } |
| 289 | + |
| 290 | + public void importFile(WebElement element, String filePath) { |
| 291 | + element.sendKeys(filePath); |
| 292 | + } |
227 | 293 | }
|
0 commit comments