Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A new method (and property) for clicking on the element via JavaScript #174

Merged
merged 1 commit into from Apr 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/main/java/com/codeborne/selenide/Configuration.java
Expand Up @@ -48,6 +48,15 @@ public class Configuration {
*/
public static boolean startMaximized = Boolean.parseBoolean(System.getProperty("selenide.start-maximized", "true"));

/**
* ATTENTION! Automatic WebDriver waiting after click isn't working in case of using this feature.
* Use clicking via JavaScript instead common element clicking.
* This solution may be helpfull for testing in Internet Explorer.
*
* Default value: false
*/
public static boolean clickViaJs = Boolean.parseBoolean(System.getProperty("selenide.click-via-js", "false"));

/**
* Does Selenide need to take screenshots on failing tests.
*
Expand Down
Expand Up @@ -236,6 +236,10 @@ else if ("click".equals(method.getName())) {
click();
return null;
}
else if ("clickViaJs".equals(method.getName())) {
clickViaJs();
return null;
}
else if ("contextClick".equals(method.getName())) {
contextClick();
return null;
Expand Down Expand Up @@ -306,7 +310,11 @@ protected boolean matches(Condition condition) {
protected void setSelected(boolean selected) {
WebElement element = waitForElement();
if (element.isSelected() ^ selected) {
element.click();
if(!clickViaJs) {
element.click();
} else {
executeJavaScript("arguments[0].click()", element);
}
}
}

Expand Down Expand Up @@ -334,7 +342,15 @@ protected WebElement waitForElement() {
}

protected void click() {
waitForElement().click();
if(!clickViaJs) {
waitForElement().click();
} else {
clickViaJs();
}
}

protected void clickViaJs() {
executeJavaScript("arguments[0].click()", waitForElement());
}

protected void contextClick() {
Expand All @@ -353,7 +369,11 @@ protected void dragAndDropTo(String targetCssSelector) {
protected void followLink() {
WebElement link = waitForElement();
String href = link.getAttribute("href");
link.click();
if(!clickViaJs) {
link.click();
} else {
executeJavaScript("arguments[0].click()", link);
}

// JavaScript $.click() doesn't take effect for <a href>
if (href != null) {
Expand Down