Klasse SeleniumManager

java.lang.Object
eu.hobbydev.bracheus.manager.SeleniumManager

public class SeleniumManager extends Object
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.
  • 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

      public void open(String url)
      Opens the specified URL in the current WebDriver instance.
      Parameter:
      url - the URL to open.
    • findElementByClass

      public org.openqa.selenium.WebElement findElementByClass(String className)
      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

      public org.openqa.selenium.WebElement findElementByID(String id)
      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

      public org.openqa.selenium.WebElement findElementByName(String name)
      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

      public org.openqa.selenium.WebElement findButtonByID(String id)
      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

      public org.openqa.selenium.WebElement findButtonByText(String text)
      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

      public org.openqa.selenium.WebElement findInputByID(String id)
      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

      public org.openqa.selenium.WebElement findInputByName(String name)
      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

      public org.openqa.selenium.WebElement findInputByClass(String className)
      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

      public org.openqa.selenium.WebElement findInputByPlaceholder(String placeholder)
      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

      public org.openqa.selenium.WebElement findDivByPlaceholder(String placeholder)
      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

      public org.openqa.selenium.WebElement findDivByID(String id)
      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

      public org.openqa.selenium.WebElement findDivByClass(String className)
      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

      public org.openqa.selenium.WebElement findDivByText(String text)
      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

      public org.openqa.selenium.WebElement findSpanByClass(String className)
      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

      public org.openqa.selenium.WebElement findLinkByText(String linkText)
      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

      public org.openqa.selenium.WebElement findCheckboxByID(String id)
      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

      public String 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

      public org.openqa.selenium.WebElement findSpanByText(String text)
      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

      public org.openqa.selenium.WebElement findByXpath(String xPath)
      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

      public List<org.openqa.selenium.WebElement> findElementsByCss(String css)
      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

      public Object executeJavascript(String script, Object... args)
      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

      public List<org.openqa.selenium.WebElement> findElementsByXpath(String xpath)
      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 WebElement objects that match the given XPath expression. If no elements are found, a SeleniagramNoSuchElementException is 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.