1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.html;
16
17 import org.htmlunit.WebDriverTestCase;
18 import org.htmlunit.junit.BrowserRunner;
19 import org.htmlunit.junit.annotation.Alerts;
20 import org.junit.Test;
21 import org.junit.runner.RunWith;
22 import org.openqa.selenium.By;
23 import org.openqa.selenium.WebDriver;
24 import org.openqa.selenium.interactions.Actions;
25
26
27
28
29
30
31
32
33
34
35 @RunWith(BrowserRunner.class)
36 public class ClickableElement2Test extends WebDriverTestCase {
37
38
39
40
41 @Test
42 @Alerts("1")
43 public void clickOnFocus() throws Exception {
44 final String html = DOCTYPE_HTML
45 + "<html><head><script>" + LOG_TITLE_FUNCTION + "</script></head><body>\n"
46 + "<form>\n"
47 + " <input type='button' id='textfield1' onfocus='log(1)'>\n"
48 + "</form>\n"
49 + "</body></html>";
50
51 final WebDriver driver = loadPage2(html);
52 driver.findElement(By.id("textfield1")).click();
53
54 verifyTitle2(driver, getExpectedAlerts());
55 }
56
57
58
59
60 @Test
61 @Alerts({"click", "click", "dblclick"})
62 public void dblClick() throws Exception {
63 final String content = DOCTYPE_HTML
64 + "<html>\n"
65 + "<head>\n"
66 + "<script>\n"
67 + LOG_TEXTAREA_FUNCTION
68 + " function clickMe() {\n"
69 + " log('click');\n"
70 + " }\n"
71 + " function dblClickMe() {\n"
72 + " log('dblclick');\n"
73 + " }\n"
74 + "</script>\n"
75 + "</head>\n"
76 + "<body id='myBody' onclick='clickMe()' ondblclick='dblClickMe()'>\n"
77 + LOG_TEXTAREA
78 + "</body></html>";
79
80 final WebDriver driver = loadPage2(content);
81
82 final Actions action = new Actions(driver);
83 action.doubleClick(driver.findElement(By.id("myBody")));
84 action.perform();
85
86 verifyTextArea2(driver, getExpectedAlerts());
87 }
88 }