Skip to content

Commit

Permalink
Use JS click() instead of a simulated mouse click to avoid 'element i…
Browse files Browse the repository at this point in the history
…s not clickable at point' (#981)
  • Loading branch information
Artur- authored Jan 29, 2018
1 parent 96e692e commit 08e8113
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.vaadin.testUI;

import com.vaadin.router.Route;
import com.vaadin.ui.event.AttachEvent;
import com.vaadin.ui.html.Div;

@Route("SVGView")
public class SVGView extends Div {

private Div placeholder;

@Override
protected void onAttach(AttachEvent attachEvent) {
super.onAttach(attachEvent);
add(placeholder = new Div());

placeholder.getElement().setProperty("innerHTML",
"<svg height=\"100\" width=\"100\">\n"
+ " <circle id='ball' cx=\"50\" cy=\"50\" r=\"40\" stroke=\"black\" stroke-width=\"3\" fill=\"red\" />\n"
+ " Sorry, your browser does not support inline SVG."
+ "</svg>");
attachEvent.getUI().getPage().executeJavaScript(
"document.getElementById('ball').addEventListener('click', function() {document.body.innerText='clicked';})");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.vaadin.tests;

import org.junit.Assert;
import org.junit.Test;
import org.openqa.selenium.By;

import com.vaadin.testUI.SVGView;
import com.vaadin.ui.Component;

public class SVGIT extends MultiBrowserTest {

@Override
protected Class<? extends Component> getTestView() {
return SVGView.class;
}

@Test
public void click() {
openTestURL();
findElement(By.id("ball")).click();
Assert.assertEquals("clicked",
findElement(By.tagName("body")).getText());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,15 @@ public void scrollLeft(int scrollLeft) {

@Override
public void click() {
autoScrollIntoView();
waitForVaadin();
wrappedElement.click();
try {
// Avoid strange "element not clickable at point" problems
callFunction("click");
} catch (Exception e) {
// SVG elements and maybe others do not have a 'click' method
autoScrollIntoView();
waitForVaadin();
wrappedElement.click();
}
}

@Override
Expand Down Expand Up @@ -258,16 +264,6 @@ public TestBenchElement findElement(By by) {
getCommandExecutor());
}

/**
* Calls the Javascript click method on the element.
*
* Useful for elements that are hidden or covered by a pseudo-element on
* some browser-theme combinations (for instance Firefox-Valo)
*/
public void clickHiddenElement() {
callFunction("click");
}

@Override
public boolean isDisplayed() {
waitForVaadin();
Expand Down

0 comments on commit 08e8113

Please sign in to comment.