InBrowserSinglton

public final class InBrowserSinglton

A simplified API built to interact with a single instance of a running browser. See com.github.loyada.jdollarx.InBrowser for an API that supports multiple browser instances.

Fields

driver

public static WebDriver driver

Methods

clickAt

public static WebElement clickAt(Path el)

Click on the location of the element that corresponds to the given path.

Parameters:
  • el – a Path instance
Returns:

the WebElement clicked at

clickOn

public static WebElement clickOn(Path el)

Click on the element that corresponds to the given path. Requires the element to be clickable.

Parameters:
  • el – a Path instance
Returns:

the WebElement clicked on

contextClick

public static WebElement contextClick(Path el)

Context click (right click) on the location of the element that corresponds to the given path.

Parameters:
  • el – a Path instance
Returns:

the WebElement clicked at

doubleClickOn

public static void doubleClickOn(Path el)

Doubleclick on the element that corresponds to the given path. Requires the element to be clickable.

Parameters:
  • el – a Path instance

dragAndDrop

public static Operations.DragAndDrop dragAndDrop(Path path)

Drag and drop in the browser. Several flavors of use:

dragAndDrop(source).to(target);
dragAndDrop(source).to(xCor, yCor);
Parameters:
  • path – the path of the element to drag and drop
Returns:

a DragAndDrop instance that allows to drag and drop to another element or to another location

find

public static WebElement find(Path el)

Equivalent to WebDriver.findElement(). If the Path contains a WebElement than it will look for an element inside that WebElement. Otherwise it looks starting at the top level. It also alters the xpath if needed to search from top level correctly.

Parameters:
  • el – a Path instance
Returns:

returns a WebElement or throws an ElementNotFoundException

findAll

public static List<WebElement> findAll(Path el)

Equivalent to WebDriver.findElements(). If the Path contains a WebElement than it will look for an element inside that WebElement. Otherwise it looks starting at the top level. It also alters the xpath if needed to search from top level correctly.

Parameters:
  • el – a Path instance
Returns:

a list of WebElements.

getCssClasses

public static List<String> getCssClasses(Path el)

Get all classes of given Path element.

Parameters:
  • el – the element to look for
Returns:

a list of classes

getSelect

public static Select getSelect(Path el)

Get a Selenium select element, which provides a high level API to interacting with a “select” menu. Since the Selenium API is good enough, there was no need to create a specialized dollarx version.

Parameters:
  • el
    • must be a “select” path, with “option” elements for the various selectable options.
Returns:

org.openqa.selenium.support.ui.Select instance

hoverOver

public static WebElement hoverOver(Path el)

Hover over on the location of the element that corresponds to the given path.

Parameters:
  • el – a Path instance
Returns:

the WebElement found

isDisplayed

public static boolean isDisplayed(Path el)

Relies on Selenium WebElement::isDisplayed, thus non-atomic.

Parameters:
  • el – the path of the element to find
Returns:

true if the element is present and displayed

isEnabled

public static boolean isEnabled(Path el)

Relies on Selenium WebElement::isEnabled, thus non-atomic.

Parameters:
  • el – the path of the element to find
Returns:

true if the element is present and enabled

isPresent

public static boolean isPresent(Path el)
Parameters:
  • el – a Path instance
Returns:

true if the element is present.

isSelected

public static boolean isSelected(Path el)

Relies on Selenium WebElement::isSelected, thus non-atomic.

Parameters:
  • el – the path of the element to find
Returns:

true if the element is present and selected

numberOfAppearances

public static Integer numberOfAppearances(Path el)

Typically should not be used directly. There are usually better options.

Parameters:
  • el – a Path instance
Returns:

tbe number of appearances of an element.

pressKeyDown

public static Operations.KeysDown pressKeyDown(CharSequence thekey)

Press key down in the browser, or on a specific element. Two flavors of use:

pressKeyDown(Keys.TAB).inBrowser();
pressKeyDown(Keys.TAB).on(path);
Parameters:
  • thekey – the key to press
Returns:

a KeysDown instance that allows to send to the browser in general or to a specific element in the DOM. See example.

releaseKey

public static Operations.ReleaseKey releaseKey(CharSequence thekey)

Release key in the browser, or on a specific element. Two flavors of use:

releaseKey(Keys.TAB).inBrowser();
releaseKey(Keys.TAB).on(path);
Parameters:
  • thekey – the key to release
Returns:

a ReleaseKey instance that allows to send to the browser in general or to a specific element in the DOM. See example.

rightClick

public static WebElement rightClick(Path el)

Context click (right click) on the location of the element that corresponds to the given path.

Parameters:
  • el – a Path instance
Returns:

the WebElement clicked at

scroll

public static Operations.Scroll scroll()

scroll the browser. Several flavors of use:

browser.scroll().to(path);
   browser.scroll().left(50);
   browser.scroll().right(50);
   browser.scroll().up(50);
   browser.scroll().down(50);
Returns:a Scroll instance that allows to scroll by offset or to a location of a DOM element

scrollElement

public static Operations.ScrollElement scrollElement(Path el)

scroll within the given element. Useful especially when working with grids.

Parameters:
  • el – a Path instance
Returns:

the WebElement found

scrollElementWithStepOverride

public static Operations.ScrollElement scrollElementWithStepOverride(Path el, int step)

scroll within the given element. Useful especially when working with grids.

Parameters:
  • el – a Path instance
  • step – step size override
Returns:

the WebElement found

scrollTo

public static WebElement scrollTo(Path el)

scroll to the location of the element that corresponds to the given path.

Parameters:
  • el – a Path instance
Returns:

the WebElement found

sendKeys

public static Operations.KeysSender sendKeys(CharSequence... charsToSend)

send keys to the browser, or to a specific element. Two flavors of use:

sendKeys("abc").toBrowser();
     sendKeys("abc").to(path);
Parameters:
  • charsToSend – the keys to send. Can be “abc”, or “a”, “b”, “c”
Returns:

a KeySender instance that allows to send to the browser in general or to a specific element in the DOM