本文整理汇总了Java中org.openqa.selenium.WebDriver.getCurrentUrl方法的典型用法代码示例。如果您正苦于以下问题:Java WebDriver.getCurrentUrl方法的具体用法?Java WebDriver.getCurrentUrl怎么用?Java WebDriver.getCurrentUrl使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openqa.selenium.WebDriver
的用法示例。
在下文中一共展示了WebDriver.getCurrentUrl方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: LoginService
import org.openqa.selenium.WebDriver; //导入方法依赖的package包/类
public LoginService(WebDriver driver) {
super(driver);
try {
URL url = new URL(driver.getCurrentUrl());
LOGOUT_URL = new URL(url.getProtocol(), url.getHost(), url.getPort(),"/logout").toString();
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}
示例2: isAlive
import org.openqa.selenium.WebDriver; //导入方法依赖的package包/类
/**
* Checks whether a browser is alive.
*
* @param webDriver WebDriver
* @return true if the given WebDriver instance is still alive.
*/
public static Boolean isAlive(WebDriver webDriver) {
try {
webDriver.getCurrentUrl();
return true;
} catch (Exception ex) {
return false;
}
}
示例3: scanCurrentPage
import org.openqa.selenium.WebDriver; //导入方法依赖的package包/类
private static void scanCurrentPage(WebDriver driver, int page) {
String current = driver.getCurrentUrl();
//Note: there was a layout change in the past on Github page
//String xpath = "//h3[@class='repo-list-name']/a";
String xpath = "//div[@class='container']//ul//h3//a";
List<WebElement> projects = driver.findElements(By.xpath(xpath));
List<String> names = projects.stream().map(p -> p.getText()).collect(Collectors.toList());
System.out.println("Going to analyze "+names.size()+" projects in this page at: "+current);
while (!names.isEmpty()) {
String name = names.remove(0);
try {
/*
do not overflow GitHub of requests. 10 per minutes should be more than enough.
Recall: "If you would like to crawl GitHub contact us at [email protected]"
from https://github.com/robots.txt
*/
Thread.sleep(6000);
} catch (InterruptedException e) {
}
By byName = By.xpath(xpath + "[text()='" + name + "']");
WebElement a = getElement(driver, byName, page);
a.click();
Boolean loaded = waitForPageToLoad(driver);
if (loaded) {
/*
Checking if either Maven or Gradle
Note: not a robust check:
- build files might not be in root folder
- no check if there was any error in the loaded page
*/
List<WebElement> maven = driver.findElements(By.xpath("//td[@class='content']//a[@title='pom.xml']"));
if (!maven.isEmpty()) {
System.out.println("" + name + " uses Maven");
} else {
List<WebElement> gradle = driver.findElements(By.xpath("//td[@class='content']//a[@title='build.gradle']"));
if (!gradle.isEmpty()) {
System.out.println("" + name + " uses Gradle");
} else {
System.out.println("" + name + " undefined build system");
}
}
}
driver.get(current);
waitForPageToLoad(driver);
}
}