Skip to content

Instantly share code, notes, and snippets.

@angiejones
Created July 14, 2019 21:07
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save angiejones/eacee133bdcf00f155343de3061091bd to your computer and use it in GitHub Desktop.
Save angiejones/eacee133bdcf00f155343de3061091bd to your computer and use it in GitHub Desktop.
Answer Key for Chapter 3 of Selenium WebDriver Java Course on Test Automation University
package base;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.List;
public class BaseTests {
private WebDriver driver;
public void setUp(){
System.setProperty("webdriver.chrome.driver", "resources/chromedriver");
driver = new ChromeDriver();
driver.get("https://the-internet.herokuapp.com/");
driver.findElement(By.linkText("Shifting Content")).click();
driver.findElement(By.linkText(("Example 1: Menu Element"))).click();
List<WebElement> menuItems = driver.findElements(By.tagName("li"));
System.out.println("Number of menu items: " + menuItems.size());
driver.quit();
}
public static void main(String args[]){
BaseTests test = new BaseTests();
test.setUp();
}
}
@Morena-s
Copy link

@MashigoJohn This is because we want to get all the lists on the page, this li (List) has the hyperlink tags inside, but if we get the hyperlinks, this will get all the hyperlinks tags on the page and we dont want to do that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment