2016-10-29 11:39:24 +02:00

62 lines
1.9 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package main.java.com.baeldung.selenium;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class SeleniumExample {
private WebDriver webDriver;
private String url = "http://www.baeldung.com/";
public SeleniumExample() {
System.setProperty("webdriver.firefox.marionette", "C:\\selenium\\geckodriver.exe");
webDriver = new FirefoxDriver();
webDriver.manage().window().maximize();
webDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
webDriver.get(url);
}
public void closeWindow() {
webDriver.close();
}
public String getTitle() {
return webDriver.getTitle();
}
public void getAboutBaeldungPage() {
closeOverlay();
clickAboutLink();
clickAboutUsLink();
}
private void closeOverlay() {
List<WebElement> webElementList = webDriver.findElements(By.tagName("a"));
try {
if (webElementList != null && !webElementList.isEmpty()) {
webElementList.stream().filter(webElement -> "Close".equalsIgnoreCase(webElement.getAttribute("title"))).findAny().orElseThrow(NoSuchElementException::new).click();
}
} catch (NoSuchElementException exception) {
exception.printStackTrace();
}
}
private void clickAboutLink() {
webDriver.findElement(By.partialLinkText("About")).click();
}
private void clickAboutUsLink() {
webDriver.findElement(By.partialLinkText("About Baeldung.")).click();
}
public boolean isAuthorInformationAvailable() {
return webDriver.findElement(By.xpath("//*[contains(text(), 'Eugen an engineer')]")).isDisplayed();
}
}