net.sf.sahi.client
Class ElementStub

java.lang.Object
  extended by net.sf.sahi.client.ElementStub

public class ElementStub
extends java.lang.Object

ElementStub is a representation of a particular HTML DOM element on the browser.
It translates to its corresponding Sahi javascript API.


Constructor Summary
ElementStub(java.lang.String elementType, Browser browser, java.lang.Object... args)
           
 
Method Summary
 ElementStub above(ElementStub aboveEl)
          Establishes a "near" relation with another element.
Eg.
 ElementStub aboveOrUnder(ElementStub aboveOrUnderEl)
           
 void blur()
           
 void check()
          Checks this element (applicable to checkboxes and radio buttons).
Internally calls browser.check(this);
 boolean checked()
          Returns true if the element is checked.
 void choose(java.lang.String value)
          Sets the value of a select element; Will unselect previously selected option(s).
This method will do nothing for elements which are not select fields.
Internally calls browser.choose(this, value, false);
 void choose(java.lang.String[] values)
          Selects multiple options of a select element; Will unselect previously selected option(s).
This method will do nothing for elements which are not select fields.
Internally calls browser.choose(this, values, false);
 void choose(java.lang.String[] values, boolean append)
          Selects multiple options of a select element; Will not unselect previously selected option(s) if append is true.
This method will do nothing for elements which are not select fields.
Internally calls browser.choose(this, values, append);
 void choose(java.lang.String value, boolean append)
          Sets the value of a select element; Will not unselect previously selected option(s) if append is true.
This method will do nothing for elements which are not select fields.
Internally calls browser.choose(this, values, append);
 void click()
          Performs a click on this element.
Internally calls browser.click(this);
 java.util.List<ElementStub> collectSimilar()
          Returns a list of element stubs similar to this one

Eg.
 boolean containsHTML(java.lang.String html)
          Returns true if the element's innerHTML contains the input html
 boolean containsText(java.lang.String text)
          Returns true if the element contains the input text
 int countSimilar()
          Returns a count of elements similar to this
 void doubleClick()
          Performs a double click on this element.
Internally calls browser.doubleClick(this);
 void dragAndDropOn(ElementStub dropElement)
          Drags the element and drops it on another element.
 void dragAndDropOn(int x, int y)
          Drags the element and drops it at the given x, y coordinate.
 boolean exists()
          Checks if an element is present on the browser.
Internally calls browser.exists(this); Retries a few times if false.
 boolean exists(boolean optimistic)
          Checks if an element is present on the browser.
Internally calls browser.exists(this);
 java.lang.String fetch()
           
 java.lang.String fetch(java.lang.String string)
          Fetches the string value of a property of this element.
Eg.
browser.div("content").fetch("innerHTML")
 void focus()
          Brings focus on the element.
 java.lang.String getAttribute(java.lang.String attribute)
           
 java.lang.String getSelectedText()
          Returns the selected text visible in a select box (<select> tag).
Same as selectedText().
Internally calls browser.getSelectedText(this);
 java.lang.String getText()
          Returns the inner text of an element.
same as text().
Internally calls browser.getText(this);
 java.lang.String getValue()
          Fetches the value of a form field from the browser.
Same as value().
Internally calls browser.getValue(this)
 void highlight()
          Highlights this element.
Internally calls browser.highlight(this);
 void hover()
          Performs a mouseover on this element.
Same as mouseOver().
Internally calls browser.mouseOver(this);
 ElementStub in(ElementStub inEl)
          Establishes an "in" relation with another element.
Eg.
 boolean isVisible()
          Checks for visibility of this element.
If an element is hidden via style display attribute set to "none" or
if the element is hidden via style visibility attribute set to "hidden",
isVisible() returns false.
 boolean isVisible(boolean optimistic)
          Checks for visibility of this element.
If an element is hidden via style display attribute set to "none" or
if the element is hidden via style visibility attribute set to "hidden",
isVisible() returns false.
 void keyDown(int keyCode, int charCode)
          Performs a keyDown on this element.
Internally calls browser.keyDown;
 void keyPress(java.lang.String keySequence, java.lang.String combo)
           
 void keyUp(int keyCode, int charCode)
          Performs a keyUp on this element.
Internally calls browser.keyUp;
 ElementStub leftOf(ElementStub leftOfEl)
           
 ElementStub leftOrRightOf(ElementStub leftOrRightOfEl)
           
 void mouseDown()
          Performs a mousedown on this element.
Internally calls browser.mouseDown(this);
 void mouseOver()
          Performs a mouseover on this element.
Same as hover().
Internally calls browser.mouseOver(this);
 void mouseUp()
          Performs a mouseup on this element.
Internally calls browser.mouseUp(this);
 ElementStub near(ElementStub nearEl)
          Establishes a "near" relation with another element.
Eg.
 ElementStub parentNode()
           
 ElementStub parentNode(java.lang.String tagName)
          Returns the first parentNode of given tagName.
Eg.
browser.link("click me").parentNode("TABLE") will ignore TDs, TRs etc.
 ElementStub parentNode(java.lang.String tagName, int occurrence)
          Returns the nth parentNode of given tagName.
 void removeFocus()
          Removes focus from the element.
 void rightClick()
          Performs a right click on this element.
Internally calls browser.rightClick(this);
 ElementStub rightOf(ElementStub rightOfEl)
           
 java.lang.String rteHTML()
          Fetches the HTML of a Rich Text Editor (RTE).
This will be browser dependent
 java.lang.String rteText()
          Fetches the text of a Rich Text Editor (RTE).
 void rteWrite(java.lang.String value)
          Writes the text into the Rich Text Editor (RTE).
Internally calls browser.rteWrite(this, value);
 java.lang.String selectedText()
          Returns the selected text visible in a select box (<select> tag).
Same as getSelectedText().
Internally calls browser.getSelectedText(this);
 void setFile(java.lang.String value)
          Sets the value of this file upload element.
This method will do nothing for elements which are not file upload fields.
Internally calls browser.setFile(this, value);
 void setFile2(java.lang.String value)
          Sets the value of this file upload element.
This method will do nothing for elements which are not file upload fields.
Internally calls browser.setFile(this, value);
 void setFile2(java.lang.String value, java.lang.String URL)
           
 void setValue(java.lang.String value)
          Sets the value of this form element.
This method will do nothing for elements which do not have a value attribute.
Internally calls browser.setValue(this, value);
 java.lang.String style(java.lang.String html)
          Returns the computed css style
eg.
 java.lang.String text()
          Returns the inner text of an element.
same as getText().
Internally calls browser.getText(this);
 java.lang.String toString()
           
 void uncheck()
          Unchecks this element (applicable to checkboxes).
Internally calls browser.uncheck(this);
 ElementStub under(ElementStub underEl)
          Establishes an "under" relation with another element.
Checks for coordinate based alignment under a particular element within a specific threshold.
Eg.
 java.lang.String value()
          Fetches the value of a form field from the browser.
Same as getValue().
Internally calls browser.getValue(this)
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ElementStub

public ElementStub(java.lang.String elementType,
                   Browser browser,
                   java.lang.Object... args)
Method Detail

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

click

public void click()
           throws ExecutionException
Performs a click on this element.
Internally calls browser.click(this);

Throws:
ExecutionException

doubleClick

public void doubleClick()
                 throws ExecutionException
Performs a double click on this element.
Internally calls browser.doubleClick(this);

Throws:
ExecutionException

rightClick

public void rightClick()
                throws ExecutionException
Performs a right click on this element.
Internally calls browser.rightClick(this);

Throws:
ExecutionException

check

public void check()
           throws ExecutionException
Checks this element (applicable to checkboxes and radio buttons).
Internally calls browser.check(this);

Throws:
ExecutionException

uncheck

public void uncheck()
             throws ExecutionException
Unchecks this element (applicable to checkboxes).
Internally calls browser.uncheck(this);

Throws:
ExecutionException

focus

public void focus()
           throws ExecutionException
Brings focus on the element.

Parameters:
element -
Throws:
ExecutionException

removeFocus

public void removeFocus()
                 throws ExecutionException
Removes focus from the element.

Parameters:
element -
Throws:
ExecutionException

dragAndDropOn

public void dragAndDropOn(ElementStub dropElement)
                   throws ExecutionException
Drags the element and drops it on another element.

Parameters:
dropElement - Element to be dropped on
Throws:
ExecutionException

dragAndDropOn

public void dragAndDropOn(int x,
                          int y)
                   throws ExecutionException
Drags the element and drops it at the given x, y coordinate.

Parameters:
dropElement - Element to be dropped on
x - X coordinate
y - Y coordinate
Throws:
ExecutionException

mouseOver

public void mouseOver()
               throws ExecutionException
Performs a mouseover on this element.
Same as hover().
Internally calls browser.mouseOver(this);

Throws:
ExecutionException

mouseDown

public void mouseDown()
               throws ExecutionException
Performs a mousedown on this element.
Internally calls browser.mouseDown(this);

Throws:
ExecutionException

mouseUp

public void mouseUp()
             throws ExecutionException
Performs a mouseup on this element.
Internally calls browser.mouseUp(this);

Throws:
ExecutionException

hover

public void hover()
           throws ExecutionException
Performs a mouseover on this element.
Same as mouseOver().
Internally calls browser.mouseOver(this);

Throws:
ExecutionException

setValue

public void setValue(java.lang.String value)
              throws ExecutionException
Sets the value of this form element.
This method will do nothing for elements which do not have a value attribute.
Internally calls browser.setValue(this, value);

Parameters:
value -
Throws:
ExecutionException

setFile

public void setFile(java.lang.String value)
             throws ExecutionException
Sets the value of this file upload element.
This method will do nothing for elements which are not file upload fields.
Internally calls browser.setFile(this, value);

Parameters:
value -
Throws:
ExecutionException

choose

public void choose(java.lang.String value)
            throws ExecutionException
Sets the value of a select element; Will unselect previously selected option(s).
This method will do nothing for elements which are not select fields.
Internally calls browser.choose(this, value, false);

Parameters:
value -
Throws:
ExecutionException

choose

public void choose(java.lang.String value,
                   boolean append)
            throws ExecutionException
Sets the value of a select element; Will not unselect previously selected option(s) if append is true.
This method will do nothing for elements which are not select fields.
Internally calls browser.choose(this, values, append);

Parameters:
value -
append: - if true, options are selected without unselecting previous options in multi-select box
Throws:
ExecutionException

choose

public void choose(java.lang.String[] values)
            throws ExecutionException
Selects multiple options of a select element; Will unselect previously selected option(s).
This method will do nothing for elements which are not select fields.
Internally calls browser.choose(this, values, false);

Parameters:
values - String array of option identifiers
Throws:
ExecutionException

choose

public void choose(java.lang.String[] values,
                   boolean append)
            throws ExecutionException
Selects multiple options of a select element; Will not unselect previously selected option(s) if append is true.
This method will do nothing for elements which are not select fields.
Internally calls browser.choose(this, values, append);

Parameters:
values - String array of option identifiers
append: - if true, options are selected without unselecting previous options in multi-select box
Throws:
ExecutionException

text

public java.lang.String text()
                      throws ExecutionException
Returns the inner text of an element.
same as getText().
Internally calls browser.getText(this);

Returns:
Throws:
ExecutionException

getText

public java.lang.String getText()
                         throws ExecutionException
Returns the inner text of an element.
same as text().
Internally calls browser.getText(this);

Returns:
Throws:
ExecutionException

rteWrite

public void rteWrite(java.lang.String value)
              throws ExecutionException
Writes the text into the Rich Text Editor (RTE).
Internally calls browser.rteWrite(this, value);

Parameters:
value -
Throws:
ExecutionException

rteText

public java.lang.String rteText()
Fetches the text of a Rich Text Editor (RTE).

Returns:
text of the RTE

rteHTML

public java.lang.String rteHTML()
Fetches the HTML of a Rich Text Editor (RTE).
This will be browser dependent

Returns:
HTML of the RTE

fetch

public java.lang.String fetch()
                       throws ExecutionException
Throws:
ExecutionException

exists

public boolean exists()
Checks if an element is present on the browser.
Internally calls browser.exists(this); Retries a few times if false. This can be controlled with script.max_reattempts_on_error in sahi.properties. Use exists(true) to return in a single try.

Returns:
true if the element exists on the browser

exists

public boolean exists(boolean optimistic)
Checks if an element is present on the browser.
Internally calls browser.exists(this);

Parameters:
optimistic: - if true will not retry till exists returns true.
Returns:
true if the element exists on the browser

value

public java.lang.String value()
                       throws ExecutionException
Fetches the value of a form field from the browser.
Same as getValue().
Internally calls browser.getValue(this)

Returns:
value of the form field
Throws:
ExecutionException

getValue

public java.lang.String getValue()
                          throws ExecutionException
Fetches the value of a form field from the browser.
Same as value().
Internally calls browser.getValue(this)

Returns:
value of the form field
Throws:
ExecutionException

selectedText

public java.lang.String selectedText()
                              throws ExecutionException
Returns the selected text visible in a select box (<select> tag).
Same as getSelectedText().
Internally calls browser.getSelectedText(this);

Returns:
selected text
Throws:
ExecutionException

isVisible

public boolean isVisible()
                  throws ExecutionException
Checks for visibility of this element.
If an element is hidden via style display attribute set to "none" or
if the element is hidden via style visibility attribute set to "hidden",
isVisible() returns false. Retries a few times if false. This can be controlled with script.max_reattempts_on_error in sahi.properties. Use exists(true) to return in a single try.

Returns:
true if the element is visible on the screen
Throws:
ExecutionException

isVisible

public boolean isVisible(boolean optimistic)
                  throws ExecutionException
Checks for visibility of this element.
If an element is hidden via style display attribute set to "none" or
if the element is hidden via style visibility attribute set to "hidden",
isVisible() returns false.

Parameters:
optimistic: - if true, Sahi will return in a single try. If false, Sahi will retry a few times.
Returns:
true if the element is visible on the screen
Throws:
ExecutionException

getSelectedText

public java.lang.String getSelectedText()
                                 throws ExecutionException
Returns the selected text visible in a select box (<select> tag).
Same as selectedText().
Internally calls browser.getSelectedText(this);

Returns:
selected text
Throws:
ExecutionException

containsText

public boolean containsText(java.lang.String text)
Returns true if the element contains the input text

Parameters:
text -
Returns:
true if the element contains the input text

containsHTML

public boolean containsHTML(java.lang.String html)
Returns true if the element's innerHTML contains the input html

Parameters:
html -
Returns:
true if the element's innerHTML contains the input html

style

public java.lang.String style(java.lang.String html)
Returns the computed css style
eg. browser.div("blackdiv").style("backgroundColor")

Parameters:
el -
attribute -
Returns:
the computed css style

in

public ElementStub in(ElementStub inEl)
Establishes an "in" relation with another element.
Eg. browser.link("delete").in(browser.cell("user1").parentNode()).click();
This clicks on the delete link in the same row as cell with content "user1"

Parameters:
inEl -
Returns:
Element with relation established

under

public ElementStub under(ElementStub underEl)
Establishes an "under" relation with another element.
Checks for coordinate based alignment under a particular element within a specific threshold.
Eg. browser.checkbox(0).near(browser.cell("Ram")).under(browser.cell("Delete user"))

Parameters:
underEl -
Returns:
Element with relation established

near

public ElementStub near(ElementStub nearEl)
Establishes a "near" relation with another element.
Eg. browser.link("delete").near(browser.cell("user1")).click();
This clicks on the delete link near a cell with content "user1"

Parameters:
nearEl -
Returns:
Element with relation established

above

public ElementStub above(ElementStub aboveEl)
Establishes a "near" relation with another element.
Eg. browser.link("delete").near(browser.cell("user1")).click();
This clicks on the delete link near a cell with content "user1"

Parameters:
nearEl -
Returns:
Element with relation established

aboveOrUnder

public ElementStub aboveOrUnder(ElementStub aboveOrUnderEl)

leftOf

public ElementStub leftOf(ElementStub leftOfEl)

rightOf

public ElementStub rightOf(ElementStub rightOfEl)

leftOrRightOf

public ElementStub leftOrRightOf(ElementStub leftOrRightOfEl)

fetch

public java.lang.String fetch(java.lang.String string)
                       throws ExecutionException
Fetches the string value of a property of this element.
Eg.
browser.div("content").fetch("innerHTML")

Returns:
Throws:
ExecutionException

checked

public boolean checked()
                throws ExecutionException
Returns true if the element is checked. Is meaningful only for radio buttons and checkboxes
Eg.
browser.radio("female").checked()

Returns:
Throws:
ExecutionException

parentNode

public ElementStub parentNode()
Returns:
the first parentNode

parentNode

public ElementStub parentNode(java.lang.String tagName)
Returns the first parentNode of given tagName.
Eg.
browser.link("click me").parentNode("TABLE") will ignore TDs, TRs etc. and will directly return the parent table.

Parameters:
tagName -
Returns:
the first parentNode of given tagName

parentNode

public ElementStub parentNode(java.lang.String tagName,
                              int occurrence)
Returns the nth parentNode of given tagName.

Parameters:
tagName -
occurrence -
Returns:

collectSimilar

public java.util.List<ElementStub> collectSimilar()
Returns a list of element stubs similar to this one

Eg.
 browser.span("/Delete/").collectSimilar()
 browser.div("css-class-name").in(browser.div("container")).collectSimilar()
 

Returns:

countSimilar

public int countSimilar()
Returns a count of elements similar to this

Returns:

keyUp

public void keyUp(int keyCode,
                  int charCode)
Performs a keyUp on this element.
Internally calls browser.keyUp;

Parameters:
keyCode -
charCode -

getAttribute

public java.lang.String getAttribute(java.lang.String attribute)
                              throws ExecutionException
Throws:
ExecutionException

blur

public void blur()
          throws ExecutionException
Throws:
ExecutionException

keyDown

public void keyDown(int keyCode,
                    int charCode)
Performs a keyDown on this element.
Internally calls browser.keyDown;

Parameters:
keyCode -
charCode -

keyPress

public void keyPress(java.lang.String keySequence,
                     java.lang.String combo)

highlight

public void highlight()
               throws ExecutionException
Highlights this element.
Internally calls browser.highlight(this);

Throws:
ExecutionException

setFile2

public void setFile2(java.lang.String value,
                     java.lang.String URL)
              throws ExecutionException
Throws:
ExecutionException

setFile2

public void setFile2(java.lang.String value)
              throws ExecutionException
Sets the value of this file upload element.
This method will do nothing for elements which are not file upload fields.
Internally calls browser.setFile(this, value);

Parameters:
value -
Throws:
ExecutionException