Package eu.hobbydev.bracheus.manager
Klasse SeleniumManager
java.lang.Object
eu.hobbydev.bracheus.manager.SeleniumManager
The `SeleniumManager` class provides methods for managing interactions with a Selenium WebDriver.
It is responsible for tasks such as initializing the WebDriver, starting and stopping the WebDriver session,
and finding elements on a webpage using various locators such as ID, class name, name, text, XPath, and CSS selectors.
This class supports automation tasks and interaction with different HTML elements on a webpage.
It also provides helper methods for JavaScript execution and page navigation.
-
Konstruktorübersicht
Konstruktoren -
Methodenübersicht
Modifizierer und TypMethodeBeschreibungexecuteJavascript(String script, Object... args) Executes a JavaScript command within the context of the current page.org.openqa.selenium.WebElementfindButtonByID(String id) Finds a button element by its ID.org.openqa.selenium.WebElementfindButtonByText(String text) Finds a button element by its visible text.org.openqa.selenium.WebElementfindByXpath(String xPath) Finds an element by its XPath.org.openqa.selenium.WebElementFinds a checkbox element by its ID.org.openqa.selenium.WebElementfindDivByClass(String className) Finds a div element by its class name.org.openqa.selenium.WebElementfindDivByID(String id) Finds a div element by its ID.org.openqa.selenium.WebElementfindDivByPlaceholder(String placeholder) Finds a div element by its placeholder text.org.openqa.selenium.WebElementfindDivByText(String text) Finds a div element by its text content.org.openqa.selenium.WebElementfindElementByClass(String className) Finds an element by its class name.org.openqa.selenium.WebElementFinds an element by its ID.org.openqa.selenium.WebElementfindElementByName(String name) Finds an element by its name.List<org.openqa.selenium.WebElement> findElementsByCss(String css) Finds multiple elements by their CSS selector.List<org.openqa.selenium.WebElement> findElementsByXpath(String xpath) Finds a list of web elements based on the provided XPath expression.org.openqa.selenium.WebElementfindInputByClass(String className) Finds an input element by its class name.org.openqa.selenium.WebElementfindInputByID(String id) Finds an input element by its ID.org.openqa.selenium.WebElementfindInputByName(String name) Finds an input element by its name.org.openqa.selenium.WebElementfindInputByPlaceholder(String placeholder) Finds an input element by its placeholder text.org.openqa.selenium.WebElementfindLinkByText(String linkText) Finds a link element by its link text.org.openqa.selenium.WebElementfindSpanByClass(String className) Finds a span element by its class name.org.openqa.selenium.WebElementfindSpanByText(String text) Finds a span element by its text content.org.openqa.selenium.JavascriptExecutorRetrieves the JavascriptExecutor from the WebDriver instance for executing JavaScript.getUrl()Retrieves the current URL of the web page that the Selenium WebDriver is currently on.voidOpens the specified URL in the current WebDriver instance.voidReloads the current webpage.voidstart()Starts the Selenium WebDriver.voidstop()Stops the Selenium WebDriver session.
-
Konstruktordetails
-
SeleniumManager
public SeleniumManager()
-
-
Methodendetails
-
start
public void start()Starts the Selenium WebDriver. If the WebDriver is not already initialized, it calls the setup method to initialize it. -
stop
public void stop()Stops the Selenium WebDriver session. If the WebDriver is initialized, it terminates the session and quits the browser. -
open
Opens the specified URL in the current WebDriver instance.- Parameter:
url- the URL to open.
-
findElementByClass
Finds an element by its class name.- Parameter:
className- the class name of the element to find.- Gibt zurück:
- the WebElement found by the specified class name.
- Löst aus:
SeleniagramNoSuchElementException- if the element is not found.
-
findElementByID
Finds an element by its ID.- Parameter:
id- the ID of the element to find.- Gibt zurück:
- the WebElement found by the specified ID.
- Löst aus:
SeleniagramNoSuchElementException- if the element is not found.
-
findElementByName
Finds an element by its name.- Parameter:
name- the name attribute of the element to find.- Gibt zurück:
- the WebElement found by the specified name.
- Löst aus:
SeleniagramNoSuchElementException- if the element is not found.
-
findButtonByID
Finds a button element by its ID.- Parameter:
id- the ID of the button element to find.- Gibt zurück:
- the WebElement representing the button.
- Löst aus:
SeleniagramNoSuchElementException- if the button is not found.
-
findButtonByText
Finds a button element by its visible text.- Parameter:
text- the visible text of the button.- Gibt zurück:
- the WebElement representing the button.
- Löst aus:
SeleniagramNoSuchElementException- if the button is not found.
-
findInputByID
Finds an input element by its ID.- Parameter:
id- the ID of the input element to find.- Gibt zurück:
- the WebElement representing the input.
- Löst aus:
SeleniagramNoSuchElementException- if the input is not found.
-
findInputByName
Finds an input element by its name.- Parameter:
name- the name attribute of the input element to find.- Gibt zurück:
- the WebElement representing the input.
- Löst aus:
SeleniagramNoSuchElementException- if the input is not found.
-
findInputByClass
Finds an input element by its class name.- Parameter:
className- the class name of the input element to find.- Gibt zurück:
- the WebElement representing the input.
- Löst aus:
SeleniagramNoSuchElementException- if the input is not found.
-
findInputByPlaceholder
Finds an input element by its placeholder text.- Parameter:
placeholder- the placeholder text of the input element to find.- Gibt zurück:
- the WebElement representing the input.
- Löst aus:
SeleniagramNoSuchElementException- if the input is not found.
-
findDivByPlaceholder
Finds a div element by its placeholder text.- Parameter:
placeholder- the placeholder text of the div element to find.- Gibt zurück:
- the WebElement representing the div.
- Löst aus:
SeleniagramNoSuchElementException- if the div is not found.
-
findDivByID
Finds a div element by its ID.- Parameter:
id- the ID of the div element to find.- Gibt zurück:
- the WebElement representing the div.
- Löst aus:
SeleniagramNoSuchElementException- if the div is not found.
-
findDivByClass
Finds a div element by its class name.- Parameter:
className- the class name of the div element to find.- Gibt zurück:
- the WebElement representing the div.
- Löst aus:
SeleniagramNoSuchElementException- if the div is not found.
-
findDivByText
Finds a div element by its text content.- Parameter:
text- the text content of the div element to find.- Gibt zurück:
- the WebElement representing the div.
- Löst aus:
SeleniagramNoSuchElementException- if the div is not found.
-
findSpanByClass
Finds a span element by its class name.- Parameter:
className- the class name of the span element to find.- Gibt zurück:
- the WebElement representing the span.
- Löst aus:
SeleniagramNoSuchElementException- if the span is not found.
-
findLinkByText
Finds a link element by its link text.- Parameter:
linkText- the link text of the anchor element to find.- Gibt zurück:
- the WebElement representing the link.
- Löst aus:
SeleniagramNoSuchElementException- if the link is not found.
-
findCheckboxByID
Finds a checkbox element by its ID.- Parameter:
id- the ID of the checkbox element to find.- Gibt zurück:
- the WebElement representing the checkbox.
- Löst aus:
SeleniagramNoSuchElementException- if the checkbox is not found.
-
getUrl
Retrieves the current URL of the web page that the Selenium WebDriver is currently on.- Gibt zurück:
- the current URL as a string.
-
findSpanByText
Finds a span element by its text content.- Parameter:
text- the text content of the span element to find.- Gibt zurück:
- the WebElement representing the span.
- Löst aus:
SeleniagramNoSuchElementException- if the span is not found.
-
findByXpath
Finds an element by its XPath.- Parameter:
xPath- the XPath of the element to find.- Gibt zurück:
- the WebElement found by the specified XPath.
- Löst aus:
SeleniagramNoSuchElementException- if the element is not found.
-
getJavaScJavascriptExecutor
public org.openqa.selenium.JavascriptExecutor getJavaScJavascriptExecutor()Retrieves the JavascriptExecutor from the WebDriver instance for executing JavaScript.- Gibt zurück:
- the JavascriptExecutor instance for the current WebDriver.
-
reloadPage
public void reloadPage()Reloads the current webpage. Refreshes the page in the current WebDriver instance. -
findElementsByCss
Finds multiple elements by their CSS selector.- Parameter:
css- the CSS selector used to locate the elements.- Gibt zurück:
- a list of WebElements matching the specified CSS selector.
- Löst aus:
SeleniagramNoSuchElementException- if no elements are found.
-
executeJavascript
Executes a JavaScript command within the context of the current page.- Parameter:
script- the JavaScript script to execute.args- optional arguments for the script.- Gibt zurück:
- the result of executing the JavaScript script.
-
findElementsByXpath
Finds a list of web elements based on the provided XPath expression. This method uses the WebDriver to search for multiple elements that match the given XPath query. If no elements are found, a custom exception is thrown.- Parameter:
xpath- The XPath expression used to locate the desired elements. The XPath should be a valid expression used to find elements within the DOM.- Gibt zurück:
- A list of
WebElementobjects that match the given XPath expression. If no elements are found, aSeleniagramNoSuchElementExceptionis thrown. - Löst aus:
SeleniagramNoSuchElementException- If no elements are found matching the given XPath. This exception is a custom exception indicating the failure to locate any matching elements.
-