当前位置: 首页>>代码示例>>Java>>正文


Java WebDriver.get方法代码示例

本文整理汇总了Java中org.openqa.selenium.WebDriver.get方法的典型用法代码示例。如果您正苦于以下问题:Java WebDriver.get方法的具体用法?Java WebDriver.get怎么用?Java WebDriver.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.openqa.selenium.WebDriver的用法示例。


在下文中一共展示了WebDriver.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parseTweets

import org.openqa.selenium.WebDriver; //导入方法依赖的package包/类
private static void parseTweets(WebDriver driver, Set<String> itemIds, String url) {
    driver.get(url);
    boolean canScroll;
    do {
        JavascriptExecutor js = ((JavascriptExecutor) driver);
        js.executeScript("window.scrollTo(0, document.body.scrollHeight)");

        List<WebElement> webElements = driver.findElements(By.cssSelector(".has-more-items"));
        canScroll = (webElements.size() > 0);
    } while (canScroll);

    List<WebElement> tweetElements =
            driver.findElements(By.cssSelector(".js-stream-item.stream-item.stream-item"));
    for (WebElement tweetElement : tweetElements) {
        String itemId = tweetElement.getAttribute("data-item-id");
        itemIds.add(itemId);
    }
}
 
开发者ID:nribeka,项目名称:twitter-stuff,代码行数:19,代码来源:SeleniumPullingSearchScreen.java

示例2: testDriver

import org.openqa.selenium.WebDriver; //导入方法依赖的package包/类
@Test
public void testDriver() throws IOException {
    WebDriver driver = new RemoteWebDriver(toUrl("http://localhost:9515"), DesiredCapabilities.chrome());
    driver.get(URL2);

    String response = driver.getPageSource();
    Document doc = Jsoup.connect(URL2).ignoreContentType(true).get();
    Elements scriptTags = doc.select("body");

    // get All functions


    try {
        String result = (String) engine.eval(response);
    } catch (ScriptException e) {
        e.printStackTrace();
    }

    log.info("PageSource " + response);

    driver.quit();
}
 
开发者ID:robevansuk,项目名称:delay-repay-bot,代码行数:23,代码来源:PhantomJSTest.java

示例3: testSelenium

import org.openqa.selenium.WebDriver; //导入方法依赖的package包/类
public static void testSelenium() throws Exception {
    System.getProperties().setProperty("webdriver.chrome.driver", "chromedriver.exe");
    WebDriver webDriver = new ChromeDriver();
    webDriver.get("http://huaban.com/");
    Thread.sleep(5000);
    WebElement webElement = webDriver.findElement(By.xpath("/html"));
    System.out.println(webElement.getAttribute("outerHTML"));
    webDriver.close();
}
 
开发者ID:CieloSun,项目名称:FashionSpider,代码行数:10,代码来源:Test.java

示例4: exercise

import org.openqa.selenium.WebDriver; //导入方法依赖的package包/类
void exercise(WebDriver driver) {
    driver.get("https://bonigarcia.github.io/selenium-jupiter/");
    assertThat(driver.getTitle(),
            containsString("A JUnit 5 extension for Selenium WebDriver"));
}
 
开发者ID:bonigarcia,项目名称:selenium-jupiter,代码行数:6,代码来源:RemoteWebDriverJupiterTest.java

示例5: test

import org.openqa.selenium.WebDriver; //导入方法依赖的package包/类
static void test() {
	System.setProperty("webdriver.chrome.driver", "D:\\selenium\\chromedriver_win32\\chromedriver.exe");
	
	WebDriver driver = new ChromeDriver();
	
	driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
	driver.manage().timeouts().pageLoadTimeout(5, TimeUnit.SECONDS);
	
	String url = "http://www.baidu.com/";

	driver.get(url);
		
		//��ȡ��ǰҳ��ȫ��iframe������iframe����Ԫ��
		try {
			List<WebElement> iframes = driver.findElements(By.tagName("iframe")); //��ȡȫ��iframe��ǩ
			if(iframes.size()!=0) {
				for(WebElement iframe : iframes) {
					if(iframe.getSize() != null) {
						  System.out.println(iframe.getAttribute("outerHtml"));
					}
				}
			}else{
				System.out.println("��ҳ�治����iframe");
			}				
		}catch(Exception e) {
			System.out.println(e);
		}
	
}
 
开发者ID:Yinqingseu,项目名称:SeleniumTest,代码行数:30,代码来源:WebdriverTest.java

示例6: main

import org.openqa.selenium.WebDriver; //导入方法依赖的package包/类
/**
 * 入口函数
 * @param args
 * @throws IOException
 */
public static void main(String[] args) throws IOException
{
	Phoenix phoenix = new Phoenix(Test.class);
	phoenix.init();
	
	WebDriver driver = phoenix.getEngine().getDriver();
	driver.get("http://baidu.com");
	
	ThreadUtil.silentSleep(3000);
	
	phoenix.close(); //关闭框架
}
 
开发者ID:LinuxSuRen,项目名称:phoenix.webui.framework.demo,代码行数:18,代码来源:Test.java

示例7: testCustomScreenshotProviderOnError

import org.openqa.selenium.WebDriver; //导入方法依赖的package包/类
@Test
public void testCustomScreenshotProviderOnError() {
    WebDriver webDriver = rule.getWebDriver();
    webDriver.get("https://www.w3schools.com/howto/howto_css_alert_buttons.asp");

    fail();
}
 
开发者ID:willhaben,项目名称:willtest,代码行数:8,代码来源:ScreenshotProviderExample.java

示例8: takeAction

import org.openqa.selenium.WebDriver; //导入方法依赖的package包/类
/**
 * Opens the NOADAPTER_URL, fills channelId input and clicks startButton
 * 
 * @return true if all browsers are ready for calls, false otherwise
 */
private boolean takeAction() {
  final String channelId = Long.toString(Math.abs(rand.nextLong()));
  for (WebDriver webDriver : this.getWebDriverList()) {
    webDriver.get(NOADAPTER_URL);
    webDriver.findElement(By.id(CHANNEL_INPUT)).sendKeys(channelId);
    webDriver.findElement(By.id(START_BUTTON)).click();
    // check that browser is ready for taking calls before initializing next one
    boolean isReady = false;
    for (int readinessTries = 0; readinessTries < TIMEOUT; readinessTries += INTERVAL) {
      isReady = readyForCalls(webDriver);
      if (isReady) {
        break;
      }
      try {
        Thread.sleep(INTERVAL);
      } catch (InterruptedException e) {
        logger.error("While testing for readiness - try number: " + readinessTries, e);
        return false;
      }
    }
    if (!isReady) {
      return false;
    }
  }
  return true;
}
 
开发者ID:webrtc,项目名称:KITE,代码行数:32,代码来源:NoAdapterTest.java

示例9: populateInfoFromNavigator

import org.openqa.selenium.WebDriver; //导入方法依赖的package包/类
/**
 * Retrieves the navigator.userAgent from all of the browser and passes it to the the respective
 * Browser object for processing.
 */
private void populateInfoFromNavigator() {
  int tupleSize = this.testConf.getTupleSize();
  if (tupleSize != this.webDriverList.size())
    return;
  for (int i = 0; i < tupleSize; i++) {
    try {
      Browser browser = this.browserList.get(i);
      if (browser.shouldGetUserAgent()) {
        WebDriver webDriver = this.webDriverList.get(i);
        if (!WebDriverFactory.isAlive(webDriver))
          webDriver.get("http://www.google.com");
        Object resultObject =
            ((JavascriptExecutor) webDriver).executeScript(userAgentScript());
        if (resultObject instanceof String) {
          String resultOfScript = (String) resultObject;
          logger.info("Browser platform and userAgent->" + resultOfScript);
          browser.setUserAgentVersionAndPlatfom(resultOfScript);
        } else {
          logger.warn("Bad result object for->" + browser.toString() + "::" + resultObject);
        }
      }
    } catch (Exception e) {
      logger.error(e);
    }
  }
}
 
开发者ID:webrtc,项目名称:KITE,代码行数:31,代码来源:TestManager.java

示例10: testEventListenerWithError

import org.openqa.selenium.WebDriver; //导入方法依赖的package包/类
@Test
public void testEventListenerWithError() {
    WebDriver webDriver = rule.getWebDriver();
    webDriver.get("https://github.com");
    WebElement searchInput = webDriver.findElement(By.cssSelector(".header-search-input"));
    searchInput.sendKeys("will", "test");
    searchInput.sendKeys(Keys.ENTER);
    String searchKeyword = webDriver.findElement(By.cssSelector(".header-search-input")).getAttribute("value");
    assertThat(searchKeyword, is("foooooo"));
}
 
开发者ID:willhaben,项目名称:willtest,代码行数:11,代码来源:EventListenerExample.java

示例11: takeAction

import org.openqa.selenium.WebDriver; //导入方法依赖的package包/类
/**
 * Opens the JITSI_URL with random room number.
 */
private void takeAction() {
    Random rand = new Random(System.currentTimeMillis());
    long channel = Math.abs(rand.nextLong());

    for (WebDriver webDriver : this.getWebDriverList()) {
        webDriver.get(JITSI_URL + channel);
    }
}
 
开发者ID:webrtc,项目名称:KITE,代码行数:12,代码来源:JitsiTest.java

示例12: downloadPic

import org.openqa.selenium.WebDriver; //导入方法依赖的package包/类
public void downloadPic(String url) {

        WebDriver driver = new ChromeDriver();

        driver.get(url);
        String html = driver.getPageSource();
        List<String> urls = parseHtmlToImages(html,picParser);
        crawlerClient.downloadPics(urls);
    }
 
开发者ID:fengzhizi715,项目名称:PicCrawler,代码行数:10,代码来源:SeleniumCrawlerClient.java

示例13: run

import org.openqa.selenium.WebDriver; //导入方法依赖的package包/类
@Override
public void run(RecordingSimulatorModule recordingSimulatorModule) {
    String baseUrl = (String) opts.get(URL);
    WebDriver driver = recordingSimulatorModule.getWebDriver();
    WebDriverWait wait = new WebDriverWait(driver, 10);
    driver.get(baseUrl + Pages.DYNAMIC_DEMO_PAGE);
    driver.findElement(By.id(CREATE_DYNAMIC_ID)).click();

    wait.until(ExpectedConditions.elementToBeClickable(By.id(LATE_CREATION_ID)));
}
 
开发者ID:hristo-vrigazov,项目名称:bromium,代码行数:11,代码来源:RecordClickCssSelectorIT.java

示例14: openWindow1

import org.openqa.selenium.WebDriver; //导入方法依赖的package包/类
@Test
public void openWindow1() throws MalformedURLException, UnexpectedException {
    createDriver();
    WebDriver driver = getWebDeriver();
    driver.get("http://www.google.com");
}
 
开发者ID:tingtaox,项目名称:googleWindowOpener,代码行数:7,代码来源:TestSuite.java

示例15: 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]b.com."
                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.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。