POTD 2: Selenium - Compute Project Grade

Due 20-May-2026, 11:59pm EST
Purpose:

Require: Java 8 (or higher), JUnit, and Selenium.

Additional resources: You may find class discussions on test automation, and characteristics of good tests helpful when designing and automating your tests.


Instruction

You may work alone or with another student in this course.

Consider Compute Project Grade app. Use the following examples to help you find and extract information from the app and imitate users' interactions.

Develop at least 5 test methods (that are different from the tests we created together in class) — be sure to use proper test oracles. Each test must target different purposes or verify different facts.

You may create a Selenium test file from scratch or use the provided computePrjGradeTest_template.java.


(Some) examples to help you find HTML elements from a web page

The following examples assume that a driver is an instance of a WebDriver and an element is an instance of a WebElement.

private WebDriver driver;
private WebElement element;

To find an HTML element by a tag name

driver.findElement(By.tagName("name-of-the-html-tag"))        

   Note: findElement() returns the first matched element.
   To find all elements that match, use findElements(). 

To find all HTML elements with as specified tag name

driver.findElements("name-of-the-html-tag"))        

   Note: findElements() returns a list of all WebElements that match the condition,
   and thus we can iterate over the list to extract information about the elements.
   For example:        

   List<WebElement> lstElem = driver.findElements(By.tagName("input")); 
   for (int i=0; i<lstElem.size(); i++)
   {
      System.out.println(i + " : " + lstElem.get(i).getAttribute("name") + " : " + 
             lstElem.get(i).getAttribute("type") + " : " + lstElem.get(i).getAttribute("value"));
   }  

To find an HTML element by a name attribute

driver.findElement(By.name("name-of-the-element"))

   Note: Each HTML element comes with a set of attributes. 
   Some attributes are applicable to certain kinds of HTML elements.   

To find an HTML element by an id attribute

driver.findElement(By.id("id-of-the-element"))

To find an HTML element using xpath (~regular expression)

// find an HTML element of type text (i.e., a textbox) 
driver.findElement(By.xpath("(//input[@type='text'])"))

// find the 2nd textbox of the page
driver.findElement(By.xpath("(//input[@type='text'])[2]"))
// an alternative way 
driver.findElement(By.xpath("(//input[@type='text'])[position()=2]"));  

// find the last textbox of the page
driver.findElement(By.xpath("(//input[@type='text'])[last()]"))

// find the one before last textbox of the page
driver.findElement(By.xpath("(//input[@type='text'])[last()-1]"))

// find an input element whose name starts with 'some-string'
driver.findElement(By.xpath("(//input[starts-with(@name, 'some-string')])"));     

// find an input element whose id starts with 'some-string'
driver.findElement(By.xpath("(//input[starts-with(@id, 'some-string')])"));     
 
// find an input element whose id = 'something'
driver.findElement(By.xpath("(//input[@id='something'])"));      

// find an element (without specifying the kind element) whose name = 'something'
driver.findElement(By.xpath("(//*[@name='something'])"));      

// find an element (without specifying the kind element) whose id = 'something'
driver.findElement(By.xpath("(//*[@id='something'])"));      
 
// find an input element whose name attribute contains 'some-string'
driver.findElement(By.xpath("//input[contains(@name, 'some-string')]"));     
 
// find an input element whose name attribute ='something1' and value attribute ='something2'
driver.findElement(By.xpath("//input[@name='something1' and @value='something2']"));     

// find an input element whose name attribute ='something1' or value attribute ='something2'
driver.findElement(By.xpath("//input[@name='something1' or @value='something2']"));     

// find all input elements of type radio (i.e, radio buttons)
driver.findElements(By.xpath("//input[@type='radio']"))

// find all elements (without specifying the kind element) of type radio (i.e, radio buttons)
driver.findElements(By.xpath("//*[@type='radio']")) 

// find all input elements of type checkbox 
driver.findElements(By.xpath("//input[@type='checkbox']"))

// find a button by text on the button
driver.findElement(By.xpath("//button[text()='text-on-the-button']"))

// find a button by partial text on the button
driver.findElement(By.xpath("//button[contains(text(), 'partial-text-on-the-button')]"))

// find a link by a link text
driver.findElement(By.linkText("link-text"))

// find a link by partial link text
driver.findElement(By.partialLinkText("partial-link-text"))  

(Some) examples to help you extract information

To find the page's title

driver.getTitle()

To retrieve the entire page page source

driver.getPageSource()

  Note: getPageSource() returns a string and 
  thus string's operations are applicable (e.g., contains("some string")) 

To get textual information of an element

element.getText() 

  Note: getText() returns a string and 
  thus string's operations are applicable (e.g., contains("some string")) 

To get a tag name of an element

element.getTagName()

To get a value of an attribute

element.getAttribute("name-of-attribute")

  Note: Some commonly used attributes are name, value, type. 

To get (x,y) coordinate of an element

element.getLocation()      
element.getLocation().getX()   
element.getLocation().getY() 

(Some) examples to imitate users' interactions

To enter input in a textbox

element.sendKeys("input-to-be-entered")

  Note: sendKeys() allows us to imitate the situation when 
  a user clicks in a textbox and enter an input. 
  Thus, we first need to find the target element before entering an input.  

To click a button, a radio button, a checkbox, or a link

element.click()


Some brief info that may help you familiarize yourself with basic web app concepts / syntax: HTML overview and intro to HTML and CSS

For a complete set of elements and attributes, please refer to W3C HTML.

Grading rubric

[Total: 10 points]: Done (or provide evidence of your attempt, full or reasonable effort)

(-2.5 points) for 24 hours late (submitted after 20-May-2026 11:59pm EST, by 21-May-2026 11:59pm EST)
(-5 points) for 48 hours late (submitted after 21-May-2026 11:59pm EST, by 22-May-2026 11:59pm EST)


Submission

Verify that the correct file is submitted.

Making your submission available to instructor and course staff is your responsibility; if we cannot access or open your file, you will not get credit. Be sure to test access to your file before the due date.


Copyright © 2026 Upsorn Praphamontripong
Released under the Creative Commons License CC-BY-NC-SA 4.0 license.
Last updated 2026-05-19 18:36