-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} |
Hi guys i wrote my code well but i dont undestand how and why do we use the By.tagName("li) the li key why are we using it??
@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
I have used the following command by accessing the web page of [Shifting Content] directly
package base;
import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
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","resources2/chromedriver.exe");
driver=new ChromeDriver();
driver.get("https://the-internet.herokuapp.com/shifting_content/menu");
}