InBrowser

public class InBrowser

A wrapper around Selenium WebDriver, used for interaction with the browser. In case only a single instance of the browser is used, com.github.loyada.jdollarx.singlebrowser.InBrowserSinglton offers a simpler API.

Constructors

InBrowser

public InBrowser(WebDriver driver)

Creates a connection to a browser, using the given driver

Parameters:
  • driver – a WebDriver instance

Methods

clickAt

public WebElement clickAt(Path el)

Click at the location the first element that fits the given path. Does not require a clickable element.

Parameters:
  • el – the element
Returns:

the clicked on WebElement

clickOn

public WebElement clickOn(Path el)

Click on the first element that fits the given path. Only works for clickable elements. If the element is currently not clickable, will wait up to a second for it to be clickable.

Parameters:
  • el – the element
Returns:

the clicked on WebElement

contextClick

public WebElement contextClick(Path el)

Context-click (right click) at the location the first element that fits the given path. Does not require a clickable element.

Parameters:
  • el – the element
Returns:

the clicked on WebElement

doubleClickOn

public void doubleClickOn(Path el)

Doubleclick the location of the first element that fits the given path.

Parameters:
  • el – the element

dragAndDrop

public Operations.DragAndDrop dragAndDrop(Path path)

Drag and drop in the browser. Several flavors of use: browser.dragAndDrop(source).to(target); browser.dragAndDrop(source).to(xCor, yCor);

Parameters:
  • path – the source element
Returns:

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

find

public WebElement find(Path el)

Finds an element in the browser, based on the xpath representing el. It is similar to WebDriver.findElement(), If el also has a WebElement (ie: getUnderlyingSource() is not empty), then it looks inside that WebElement. This is useful also to integrate with existing WebDriver code.

Parameters:
  • el
    • the path to find
Returns:

  • A WebElement instance from selenium, or throws NoSuchElementException exception

findAll

public List<WebElement> findAll(Path el)

Finds all elements in the browser, based on the xpath representing el. It is similar to WebDriver.findElements(), If el also has a WebElement (ie: getUnderlyingSource() is not empty), then it looks inside that WebElement. This is useful also to integrate with existing WebDriver code.

Parameters:
  • el
    • the path to find
Returns:

  • A list of WebElement from selenium, or throws NoSuchElementException exception

findPageWithNumberOfOccurrences

public WebElement findPageWithNumberOfOccurrences(Path el, int numberOfOccurrences, RelationOperator relationOperator)

Don’t use this directly. There are better ways to do equivalent operation.

Parameters:
  • el – the path to find
  • numberOfOccurrences – the base number to find
  • relationOperator – whether we look for exactly the numberOfOccurrences, at least, or at most occurrences
Returns:

the first WebElement found

findPageWithout

public WebElement findPageWithout(Path el)

Finds an page in the browser, that does not contain the given path

Parameters:
  • el
    • the path that must not appear in the page
Returns:

returns the page element or raises NoSuchElementException

getCssClasses

public List<String> getCssClasses(Path el)

Get all classes of given Path element.

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

a list of classes

getDriver

public WebDriver getDriver()
Returns:the underlying WebDriver instance

getSelect

public 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 WebElement hoverOver(Path el)

Hover over the location of the first element that fits the given path

Parameters:
  • el – the element
Returns:

the clicked on WebElement

isDisplayed

public boolean isDisplayed(Path el)

is the element present and displayed? Typically you should not use this method directly. Instead, use CustomMatchers. Also, this is limited to checking the inlined css style, so it is quite limited.

Parameters:
  • el – the element
Returns:

true if it is present and selected

isEnabled

public boolean isEnabled(Path el)

is the element present and enabled? Typically you should not use this method directly. Instead, use CustomMatchers.

Parameters:
  • el – the element
Returns:

true if it is present and enabled

isNotPresent

public boolean isNotPresent(Path el)

is the element present? Typically you should not use this method directly. Instead, use CustomMatchers.

Parameters:
  • el – the path to find
Returns:

true if it is not present

isPresent

public boolean isPresent(Path el)

is the element present? Typically you should not use this method directly. Instead, use CustomMatchers.

Parameters:
  • el – the path to find
Returns:

true if the element is present

isSelected

public boolean isSelected(Path el)

is the element present and selected? Typically you should not use this method directly. Instead, use CustomMatchers.

Parameters:
  • el – the element
Returns:

true if it is present and selected

numberOfAppearances

public Integer numberOfAppearances(Path el)

Returns the number of elements in the browser that match the given path. Typically you should not use this method directly. Instead, use CustomMatchers.

Parameters:
  • el – the element to find
Returns:

the number of elements in the browser that match the given path

pressKeyDown

public Operations.KeysDown pressKeyDown(CharSequence thekey)

Press key down in the browser, or on a specific element. Two flavors of use: browser.pressKeyDown(Keys.TAB).inBrowser(); browser.pressKeyDown(Keys.TAB).on(path);

Parameters:
  • thekey – a key to press
Returns:

returns a KeysDown instance that allows to press a key on the browser in general or on a specific DOM element

releaseKey

public Operations.ReleaseKey releaseKey(CharSequence thekey)

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

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

returns a ReleaseKey instance that allows to release on the browser in general or on a specific DOM element

rightClick

public WebElement rightClick(Path el)

Context-click (right click) at the location the first element that fits the given path. Does not require a clickable element.

Parameters:
  • el – the element
Returns:

the clicked on WebElement

scroll

public 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 Operations.ScrollElement scrollElement(Path wrapper)

scrollElementWithStepOverride

public Operations.ScrollElement scrollElementWithStepOverride(Path wrapper, int step)

scrollTo

public WebElement scrollTo(Path el)

Scroll to the location of the first element that fits the given path

Parameters:
  • el – the element
Returns:

the clicked on WebElement

sendKeys

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

send keys to the browser, or to a specific element. Two flavors of use: browser.sendKeys(“abc”).toBrowser(); browser.sendKeys(“abc”).to(path);

Parameters:
  • charsToSend – The characters to send. Can be “abc” or “a”, “b”, “c”
Returns:

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