當前位置: 首頁>>代碼示例>>Java>>正文


Java WebDriver.getCurrentUrl方法代碼示例

本文整理匯總了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);
    }
}
 
開發者ID:axibase,項目名稱:atsd-web-test,代碼行數:10,代碼來源:LoginService.java

示例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;
  }
}
 
開發者ID:webrtc,項目名稱:KITE,代碼行數:15,代碼來源:WebDriverFactory.java

示例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);
    }
}
 
開發者ID:arcuri82,項目名稱:testing_security_development_enterprise_systems,代碼行數:58,代碼來源:GitCrawler.java


注:本文中的org.openqa.selenium.WebDriver.getCurrentUrl方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。