public class DocumentClickCapture
extends java.lang.Object
implements java.lang.Runnable
Usage:
DocumentClickCapture listener = new DocumentClickCapture();
try{
MouseEvent event = listener.waitForClick(timeout_in_seconds);
// do stuff with event info
// use again if desired
event = listener.waitForClick(timeout_in_seconds);
// do stuff with event info
}catch(Exception x){
// handle them here
}
The use CAN allow the application's event handlers to see the events if the alternate constructor is used setting the allowPropogation boolean to true:
Usage:
DocumentClickCapture listener = new DocumentClickCapture(true);
try{
MouseEvent event = listener.waitForClick(timeout_in_seconds);
// do stuff with event info
// use again if desired
event = listener.waitForClick(timeout_in_seconds);
// do stuff with event info
}catch(Exception x){
// handle them here
}
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_DELAY_WAIT_READY_LOOP
in a loop, default delay time (in milliseconds) to sleep before trying to detect the
click event-ready (event information has be retrieved from page by javascript) another time.
|
static boolean |
DEFAULT_IGNORE_EVENT_INFORMATION
true, will not retrieve event's information.
|
static int |
DEFAULT_TIMEOUT_BETWEEN_EVENT_FIRE_AND_READY
After event-fired, default timeout (5000 milliseconds) before click event-ready (event information has be retrieved from page by javascript).
|
static int |
delayWaitReady
in a loop, time (in milliseconds) to sleep before trying to detect the
click event-ready (event information has be retrieved from page by javascript) another time.
|
static boolean |
ENABLE_CLICK_CAPTURE
This field could be used to turn on/off the DocumentClickCapture.
This field will ONLY affect the new instance of DocumentClickCapture. |
static java.lang.String |
LISTENER_ID_ROOT
"safs_clickcapture"
|
static int |
LISTENER_LOOP_DELAY
in a loop, time (in milliseconds) to sleep before trying to detect the click event-fired on page another time.
|
static int |
timeoutBtwEvtFireAndReady
Only
eventFired is set to true, this field will take effect.after event-fired, in a loop, timeout (in milliseconds) before click event-ready (event information has be retrieved from page by javascript). |
Constructor and Description |
---|
DocumentClickCapture()
Default constructor.
|
DocumentClickCapture(boolean allowPropogation)
Alternate constructor.
|
DocumentClickCapture(boolean allowPropogation,
org.openqa.selenium.WebElement target)
Alternate constructor.
|
Modifier and Type | Method and Description |
---|---|
(package private) java.lang.String |
_addEventListeners()
Attach event-listeners to a target.
|
(package private) java.lang.String |
_removeEventListeners()
Remove the attached event-listeners from a target.
|
void |
addListeners(boolean startListening)
Inject the Document level event listeners if they are not already injected.
Does nothing if the listeners are already injected. This method will also start the polling thread to watch the javascript variable used to monitor 'click event' if it is called with parameter true. |
java.lang.String |
getListenerID() |
boolean |
isEnlargeListeningArea()
If true, we will use the document as the click-event-receiver.
If false, we will use the specific component as the click-event-receiver. |
static boolean |
isIgnoreEventInformation()
|
void |
run()
Internal Runnable use only.
|
void |
setEnabled(boolean enabled)
|
void |
setEnlargeListeningArea(boolean enlargeListeningArea)
This should be called before calling
startListening() , if we wantenlargeListeningArea works as expected. |
static void |
setIgnoreEventInformation(boolean ignoreEventInformation)
|
void |
startListening()
Start the polling thread to watch the javascript variable used to monitor 'click event'.
Before starting the polling thread, this listener will be disabled if the JavaScript "Alert" is present. This method should be called after calling addListeners(boolean) (addListeners() is called with false).The following is an example: |
void |
stopListening()
Stop the pollingThread from listening and remove the listeners.
|
MouseEvent |
waitForClick(long secondsTimeout) |
public static final java.lang.String LISTENER_ID_ROOT
public static int LISTENER_LOOP_DELAY
public static final int DEFAULT_TIMEOUT_BETWEEN_EVENT_FIRE_AND_READY
timeoutBtwEvtFireAndReady
,
Constant Field Valuespublic static final int DEFAULT_DELAY_WAIT_READY_LOOP
public static int timeoutBtwEvtFireAndReady
eventFired
is set to true, this field will take effect.eventFired
,
waitForClick(long)
public static int delayWaitReady
waitForClick(long)
public static final boolean DEFAULT_IGNORE_EVENT_INFORMATION
public static boolean ENABLE_CLICK_CAPTURE
DocumentClickCapture.ENABLE_CLICK_CAPTURE = true; DocumentClickCapture captureA = new DocumentClickCapture(true, target); DocumentClickCapture.ENABLE_CLICK_CAPTURE = false; DocumentClickCapture captureB = new DocumentClickCapture(true, target); DocumentClickCapture captureC = new DocumentClickCapture(true, target); captureA is enabled; while captureB and captureC will be disabled.
public DocumentClickCapture()
public DocumentClickCapture(boolean allowPropogation)
DocumentClickCapture()
public DocumentClickCapture(boolean allowPropogation, org.openqa.selenium.WebElement target)
DocumentClickCapture(boolean)
public static boolean isIgnoreEventInformation()
public static void setIgnoreEventInformation(boolean ignoreEventInformation)
public void setEnabled(boolean enabled)
enabled
- startListening()
,
waitForClick(long)
public boolean isEnlargeListeningArea()
enlargeListeningArea
public void setEnlargeListeningArea(boolean enlargeListeningArea)
startListening()
, if we wantenlargeListeningArea
works as expected.enlargeListeningArea
- enlargeListeningArea
public void addListeners(boolean startListening) throws SeleniumPlusException
DocumentClickCapture listener = new DocumentClickCapture();
try{
//Add the listener and start the polling thread automatically.
listener.addListeners(true);
//do click action;
...
MouseEvent event = listener.waitForClick(timeout_in_seconds);
}catch(Exception x){
// handle them here
}
If the click action may cause JS "Alert" pops up, we should call this methods with parameter falsestartListening()
later. The example code is listed below:
DocumentClickCapture listener = new DocumentClickCapture();
try{
//Add the listener
listener.addListeners(false);
//do click action;
...
//Start listening
listener.startListening();
MouseEvent event = listener.waitForClick(timeout_in_seconds);
}catch(Exception x){
// handle them here
}
startListening
- boolean, If true, start polling thread automatically;
otherwise, will not start it and user needs to start it by calling startListening()
.SeleniumPlusException
waitForClick(long)
,
addEventListeners()
public void startListening()
addListeners(boolean)
(addListeners() is called with false).
DocumentClickCapture listener = new DocumentClickCapture();
try{
//Add the listener
listener.addListeners(false);
//do click action;
...
//Start listening
listener.startListening();
MouseEvent event = listener.waitForClick(timeout_in_seconds);
}catch(Exception x){
// handle them here
}
addListeners(boolean)
public void stopListening()
public MouseEvent waitForClick(long secondsTimeout) throws java.lang.IllegalArgumentException, java.lang.InterruptedException, SeleniumPlusException
secondsTimeout
- -- timeout in seconds before throwing InterruptedExceptionjava.lang.InterruptedException
- if timeout has been reached.java.lang.IllegalArgumentException
- if secondsTimeout is < 1.SeleniumPlusException
- if we could not add or remove eventListeners in the browser.addListeners(boolean)
public void run()
This thread monitors the javascript event flag to be set indicating the event was fired. monitor loop can be stopped internally with setRunning(false). If the event is detected the onEventFired() method is invoked by this thread. This is a single-fire event. Once fired or stopped the monitor will exit and the remote EventListeners will be removed from the EventTarget.
run
in interface java.lang.Runnable
public java.lang.String getListenerID()
java.lang.String _addEventListeners()
domelement
- (Javascript) Object, the dom-element to attach the event-listeners.addEventListeners()
java.lang.String _removeEventListeners()
domelement
- (Javascript) Object, the dom-element to detach the event-listeners.removeEventListeners()
Copyright © SAS Institute. All Rights Reserved.