2016-08-30 22:04:37 +05:30
|
|
|
|
package main.java.com.baeldung.selenium;
|
|
|
|
|
|
2016-10-07 18:16:04 +05:30
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
|
|
import org.openqa.selenium.By;
|
2016-08-30 22:04:37 +05:30
|
|
|
|
import org.openqa.selenium.WebDriver;
|
2016-10-07 18:16:04 +05:30
|
|
|
|
import org.openqa.selenium.WebElement;
|
2016-08-30 22:04:37 +05:30
|
|
|
|
import org.openqa.selenium.firefox.FirefoxDriver;
|
|
|
|
|
|
|
|
|
|
public class SeleniumExample {
|
|
|
|
|
|
|
|
|
|
private WebDriver webDriver;
|
2016-10-02 18:01:49 +05:30
|
|
|
|
private String url = "http://www.baeldung.com/";
|
2016-10-07 18:16:04 +05:30
|
|
|
|
|
2016-08-30 22:04:37 +05:30
|
|
|
|
public SeleniumExample() {
|
|
|
|
|
webDriver = new FirefoxDriver();
|
2016-10-07 18:16:04 +05:30
|
|
|
|
webDriver.manage().window().maximize();
|
|
|
|
|
webDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
|
2016-08-30 22:04:37 +05:30
|
|
|
|
webDriver.get(url);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void closeWindow() {
|
|
|
|
|
webDriver.close();
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-02 18:01:49 +05:30
|
|
|
|
public String getTitle() {
|
2016-08-30 22:04:37 +05:30
|
|
|
|
return webDriver.getTitle();
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-07 18:16:04 +05:30
|
|
|
|
public void getAboutBaeldungPage() {
|
|
|
|
|
closeOverlay();
|
|
|
|
|
clickAboutLink();
|
|
|
|
|
clickAboutUsLink();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void closeOverlay() {
|
|
|
|
|
List<WebElement> webElementList = webDriver.findElements(By.tagName("a"));
|
|
|
|
|
if (webElementList != null && !webElementList.isEmpty()) {
|
2016-10-09 08:15:55 +05:30
|
|
|
|
webElementList.stream().filter(webElement -> "Close".equalsIgnoreCase(webElement.getAttribute("title"))).findAny().get().click();
|
2016-10-07 18:16:04 +05:30
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 <20> an engineer')]"))
|
|
|
|
|
.isDisplayed();
|
|
|
|
|
}
|
2016-08-30 22:04:37 +05:30
|
|
|
|
}
|