Skip to content

Instantly share code, notes, and snippets.

@Denilson-Semedo
Last active June 8, 2023 01:30
Show Gist options
  • Save Denilson-Semedo/f8975fe93b3d516e2ae36d7b15867931 to your computer and use it in GitHub Desktop.
Save Denilson-Semedo/f8975fe93b3d516e2ae36d7b15867931 to your computer and use it in GitHub Desktop.
Selenium

Selenium

Selenium is an open-source framework widely used for automating web browsers. It provides a suite of tools and libraries that enable testers and developers to automate browser actions, interact with web elements, and perform functional testing of web applications. Selenium supports various programming languages such as Java, C#, Python, Ruby, and JavaScript, making it accessible to a wide range of developers.

Selenium Documentation

Topic Description
What is Selenium? Selenium is an open-source framework for automating web browsers. It allows testers to write tests in various programming languages.
Selenium Components Selenium WebDriver, Selenium IDE, Selenium Grid
Supported Programming Languages Java, C#, Python, Ruby, JavaScript, etc.
Key Features Cross-browser compatibility, multi-language support, easy integration with testing frameworks, support for parallel testing, extensive community support
Selenium WebDriver Core component for interacting with web elements and automating browser actions
Selenium IDE Integrated Development Environment (IDE) for recording and playing back browser interactions
Selenium Grid Distributed testing framework for running tests on multiple machines or browsers simultaneously
Browser Compatibility Chrome, Firefox, Safari, Internet Explorer, Edge, Opera, etc.
Test Framework Integration TestNG, JUnit, NUnit, PyTest, etc.
Advantages of Selenium Open-source, platform independence, supports multiple programming languages, extensive community and documentation support, cross-browser testing
Limitations of Selenium Limited support for desktop applications, no support for CAPTCHA automation, steep learning curve for beginners

Spreedsheet

Command/Function Description Example
Navigation
get(url) Loads a web page with the given URL. driver.get("https://www.example.com")
navigate().to(url) Loads a web page with the given URL. driver.navigate().to("https://www.example.com")
Element Identification
findElement(by) Locates the first element matching the specified locator strategy. WebElement element = driver.findElement(By.id("username"))
findElements(by) Locates all elements matching the specified locator strategy. List<WebElement> elements = driver.findElements(By.tagName("a"))
Element Interactions
click() Clicks on the element. element.click()
sendKeys(text) Enters text into an input field or text area. element.sendKeys("Hello, World!")
getText() Retrieves the visible text of an element. String text = element.getText()
Assertions and Verifications
assertEquals(expected, actual) Asserts that two values are equal. assertEquals("Title", driver.getTitle())
assertTrue(condition) Asserts that a condition is true. assertTrue(element.isDisplayed())
Wait and Synchronization
implicitlyWait(timeout, unit) Sets a default waiting time for the element to appear. driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS)
WebDriverWait Waits for a specific condition before proceeding. WebDriverWait wait = new WebDriverWait(driver, 10)
Browser Manipulation
switchTo().frame(name) Switches the focus to a frame with the specified name or index. driver.switchTo().frame("frameName")
getWindowHandle() Retrieves the unique identifier of the current browser window. String windowHandle = driver.getWindowHandle()
Browser Navigation
navigate().back() Navigates the browser back to the previous page. driver.navigate().back()
navigate().forward() Navigates the browser forward to the next page. driver.navigate().forward()
Browser Actions
sendKeys(Keys.RETURN) Sends the Enter/Return key to the browser. element.sendKeys(Keys.RETURN)
Actions Performs advanced user interactions using the Actions class. Actions actions = new Actions(driver)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment