Skip to content

Commit

Permalink
[web]
Browse files Browse the repository at this point in the history
- [`clickOffset(locator,x,y)`]: **NEW** command to click on a target web element by its offset.

Signed-off-by: automike <[email protected]>
  • Loading branch information
mikeliucc committed Feb 3, 2019
1 parent 8fd42dc commit 5e79cdb
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/main/java/org/nexial/core/plugins/web/WebCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,33 @@ public StepResult clickByLabelAndWait(String label, String waitMs) {
return clickAndWait(xpath, waitMs);
}

public StepResult clickOffset(String locator, String x, String y) {
requiresPositiveNumber(x, "Invalid value for x", x);
requiresPositiveNumber(y, "Invalid value for y", y);

WebElement element;
try {
List<WebElement> matches = findElements(locator);
element = CollectionUtils.isEmpty(matches) ? null : matches.get(0);
if (element == null) { return StepResult.fail("No element via locator '" + locator + "'"); }

ConsoleUtils.log("clicking '" + locator + "'...");
highlight(element);

int offsetX = NumberUtils.toInt(x);
int offsetY = NumberUtils.toInt(y);
new Actions(driver).moveToElement(element, offsetX, offsetY).click().build().perform();
return StepResult.success("clicked on web element at offset (" + x + "," + y + ")");
} catch (TimeoutException e) {
return StepResult.fail("Unable to find element via locator '" + locator + "' within allotted time");
} catch (Exception e) {
return StepResult.fail(e.getMessage(), e);
} finally {
// could have alert text...
alert.preemptiveDismissAlert();
}
}

public StepResult doubleClickByLabel(String label) {
return doubleClickByLabelAndWait(label, context.getPollWaitMs() + "");
}
Expand Down

0 comments on commit 5e79cdb

Please sign in to comment.