Skip to content

Selenium

Ben Weese edited this page Jun 13, 2019 · 2 revisions

Selenium is used to automate browsers. This is widely used and accepted as a framework to automate browsers for clicking, inputting and several other options. Most other frameworks used to automate browsers are based on Selenium.

import org.openqa.selenium.WebDriver;

So the WebDriver is widely supported by the browsers and you can normally download one. For this automation we are using the Chrome Driver. You can see how the the Driver was Setup in the Setup page of this wiki. Remember to call driver.quit(); at the end of the test so the browser window closes.

The driver is used to access parts of the webpage such as driver.getCurrentUrl() gets the current URL of the window you are in. driver.findElement(comPOM.button); is the WebElement you are wanting to connect to.

import org.openqa.selenium.WebElement;

WebElements are different components on the page we can grab and interact with. So in the above example you could use WebElement element = driver.findElement(comPOM.button); and now the element is something we have access to. So we can call an element.click(); to click the button or a element.sendKeys("string"); if we wanted to input characters into a text box. Below are several other things we can do:

  • element.isDisplayed() returns a boolean
  • element.submit() submits the form

import org.openqa.selenium.By;

By allows us to fine the element we want by an ID, Class Name, Name, XPath, CSS Selector, and various other labels you can find but using chrome's inspector to look at the HTML.

Clone this wiki locally