selenium

Topics related to selenium:

Getting started with selenium

Selenium is a powerful library of commands in multiple languages (C#, Haskell, Java, JavaScript, Objective-C, Perl, PHP, Python, R, and Ruby) that allow a programmer to automate browser interaction. This is incredibly useful for developers testing applications.

Selenium offers methods to:

  • Find an Element in a webpage
  • Click on an Element
  • Send a String to an Element
  • Navigate to a web page
  • Change to a different tab in the same browser window
  • Take a screenshot of a webpage

Using these methods, a developer can have automatic tests checking:

  • If an Element is in a page, and visible to a user
  • A search or login form
  • Buttons or interactive Elements
  • Check the values or attributes of an Element

Selenium runs in webdrivers, which are similar to a normal web browser but allow Selenium to interact with them. A Selenium test typically opens up a new driver instance of whatever browser the developer is testing in, which is always a clean slate. This way, when running a Selenium test, the developer does not have to worry about previous cookies, or a browser cache affecting the results of their application.

Selenium also works when running a webdriver in headless mode.

Selenium simple example C# and Nunit

This is a very basic example or starting Selenium, accessing and using a page and then shutting down Selenium within NUnit.

Selenium simple example C# and Nunit

Getting started with Selenium in python

What is Selenium?

Selenium is a library of commands to help a programmer interface with a browser like a real user.

Things that Selenium does:

Finding element(s) in a webpage's html

  • Finds a single element:

  • Finds a list of elements:

    • driver.find_elements_by_css_selector("css.selector.of.elements")
    • driver.find_elements_by_xpath("//xpath//of//elements")
    • driver.find_elements_by_name("name_of_elements")
    • driver.find_elements_by_partial_link_text("elements_link_text")
    • driver.find_elements_by_class_name("class_name_of_elements")
    • driver.find_elements_by_tag_name("tag_name_of_elements")
  • Official documentation: selenium-python read the docs

Interact with elements:

"method" represents any of the above methods to find an element or list of elements.

  • click function:

    • driver.find_element_by_method.click()
  • send_keys function:

    • driver.find_element_by_method.send_keys("text") sends the String "text" to the element found.
    • driver.find_element_by_method.send_keys(KeyCode.UP) sends the KeyCode for the up arrow key to the element found.

Accepting popup alerts with Selenium

Take a screenshot of a webpage

Waiting in Selenium

Selenium IDE

WebDriver Factory

Mobile app automation

First project in selenium with Java

WebDriverManager for Selenium - a very neat tool from Boni Garcia