当前位置: 首页>>代码示例>>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;未经允许,请勿转载。