Example Absolute and Relative Paths for Selenium WebDriver
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class AbsoluteRelativePaths {
@Test
public void absolutePath() throws InterruptedException {
System.setProperty("webdriver.chrome.driver", "E:\\Selenium\\chromedriver_win32\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("E:\\Selenium\\absolute.html");
// Absolute Path starts from root path
WebElement link1 = driver.findElement(By.xpath("/html/body/li[@id='test']/a"));
// Relative Path starts from current path
WebElement link2 = driver.findElement(By.xpath(".//*[@id='test']/a"));
driver.quit();
}
}
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class AbsoluteRelativePaths {
@Test
public void absolutePath() throws InterruptedException {
System.setProperty("webdriver.chrome.driver", "E:\\Selenium\\chromedriver_win32\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("E:\\Selenium\\absolute.html");
// Absolute Path starts from root path
WebElement link1 = driver.findElement(By.xpath("/html/body/li[@id='test']/a"));
// Relative Path starts from current path
WebElement link2 = driver.findElement(By.xpath(".//*[@id='test']/a"));
driver.quit();
}
}
No comments:
Post a Comment