本文整理了Java中org.openqa.selenium.WebDriver.get()
方法的一些代码示例,展示了WebDriver.get()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebDriver.get()
方法的具体详情如下:
包路径:org.openqa.selenium.WebDriver
类名称:WebDriver
方法名:get
[英]Load a new web page in the current browser window. This is done using an HTTP GET operation, and the method will block until the load is complete. This will follow redirects issued either by the server or as a meta-redirect from within the returned HTML. Should a meta-redirect "rest" for any duration of time, it is best to wait until this timeout is over, since should the underlying page change whilst your test is executing the results of future calls against this interface will be against the freshly loaded page. Synonym for org.openqa.selenium.WebDriver.Navigation#to(String).
[中]在当前浏览器窗口中加载新网页。这是使用HTTP GET操作完成的,该方法将阻塞,直到加载完成。这将遵循服务器发出的重定向,或者作为返回HTML中的元重定向。如果一个元重定向“rest”一段时间,最好等到这个超时结束,因为如果在测试执行过程中基础页面发生了变化,那么对这个接口的未来调用的结果将针对新加载的页面。组织的同义词。openqa。硒。网络驱动程序。导航#到(字符串)。
代码示例来源:origin: apache/geode
@Override
public void before() throws Throwable {
setUpWebDriver();
try {
driver.get(getPulseURL() + "login.html");
} catch (Exception e) {
e.printStackTrace();
System.out.println("before: driver get exception " + e.getMessage());
throw e;
}
if (StringUtils.isNotBlank(username) && StringUtils.isNotBlank(password)) {
try {
login();
} catch (Exception e) {
e.printStackTrace();
System.out.println("before: login exception " + e.getMessage());
throw e;
}
}
driver.navigate().refresh();
}
代码示例来源:origin: cloudfoundry/uaa
@Test
public void checkAccessForTotpPage() throws Exception {
webDriver.get(zoneUrl + "/logout.do");
webDriver.manage().deleteAllCookies();
webDriver.get(zoneUrl + "/login/mfa/register");
assertEquals(zoneUrl + "/login", webDriver.getCurrentUrl());
}
代码示例来源:origin: apache/geode
private void login() {
WebElement userNameElement = waitForElementById("user_name", 60);
WebElement passwordElement = waitForElementById("user_password");
userNameElement.sendKeys(username);
passwordElement.sendKeys(password);
passwordElement.submit();
driver.get(getPulseURL() + "clusterDetail.html");
WebElement userNameOnPulsePage =
(new WebDriverWait(driver, 30, 1000)).until(
(ExpectedCondition<WebElement>) d -> d.findElement(By.id("userName")));
assertNotNull(userNameOnPulsePage);
}
代码示例来源:origin: cloudfoundry/uaa
@Test
public void testFrameReportsChangedWhenSameUser_whenLoggedOut() throws UnsupportedEncodingException, InterruptedException {
webDriver.get(testPage);
webDriver.findElement(By.id("sameUser")).click();
assertMessage("unchanged");
}
代码示例来源:origin: org.juzu/juzu-core
@Test
@RunAsClient
public void test() throws Exception {
driver.get(applicationURL().toString());
System.out.println(driver.getPageSource());
WebDriverWait wait = new WebDriverWait(driver, 5);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("/html[@bar]")));
WebElement elt = driver.findElement(By.tagName("html"));
assertEquals("<bar>foo_value</bar>", elt.getAttribute("bar"));
}
}
代码示例来源:origin: stackoverflow.com
LogEntries logEntries = driver.manage().logs().get(LogType.BROWSER);
for (LogEntry entry : logEntries) {
System.out.println(new Date(entry.getTimestamp()) + " " + entry.getLevel() + " " + entry.getMessage());
driver.get("http://mypage.com");
代码示例来源:origin: stackoverflow.com
WebDriver driver = new FirefoxDriver();
driver.get("http://www.reddit.com/r/pics/");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
WebElement element = driver.findElement(By
.linkText("next ›"));
element.click();
System.out.println(driver.getCurrentUrl());
代码示例来源:origin: stackoverflow.com
public void handle(){
WebDriver driver;
driver=new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://toolsqa.com/automation-practice-switch-windows/");
driver.findElement(By.xpath(".//*[@id='content']/p[4]/button")).click();
ArrayList<String> tabs2 = new ArrayList<String> (driver.getWindowHandles());
driver.switchTo().window(tabs2.get(1));
System.out.println(driver.getTitle());
}
代码示例来源:origin: stackoverflow.com
WebDriver driver = new FirefoxDriver();
driver.get("file://<Path>/div.html");
long starttime = System.currentTimeMillis();
//driver.findElement(By.cssSelector(".class"));
//driver.findElement(By.className("class"));
//driver.findElement(By.cssSelector("#id"));
//driver.findElement(By.id("id"));
//driver.findElement(By.cssSelector("div"));
//driver.findElement(By.tagName("div"));
long stoptime = System.currentTimeMillis();
System.out.println(stoptime-starttime + " milliseconds");
driver.quit();
代码示例来源:origin: spring-projects/spring-security
@Test
public void cookies() {
WebTestClient webTestClient = WebTestClient
.bindToController(new CookieController())
.build();
WebDriver driver = WebTestClientHtmlUnitDriverBuilder
.webTestClientSetup(webTestClient).build();
driver.get("http://localhost/cookie");
assertThat(driver.getPageSource()).contains("theCookie");
driver.get("http://localhost/cookie/delete");
assertThat(driver.getPageSource()).contains("null");
}
代码示例来源:origin: cloudfoundry/uaa
@Test
public void testMethodNotAllowedRoutedToErrorPage() throws Exception {
webDriver.get(baseUrl + "/authenticate");
Assert.assertTrue("Check if on the error page", webDriver.findElement(By.tagName("h2")).getText().contains("Uh oh."));
Assert.assertTrue("Check if on the error page", webDriver.findElement(By.tagName("h2")).getText().contains("Something went amiss."));
}
}
代码示例来源:origin: cloudfoundry/uaa
@Test
public void testCsrfIsResetDuringLoginPageReload() {
webDriver.get(baseUrl + "/login");
String csrf1 = webDriver.manage().getCookieNamed(CookieBasedCsrfTokenRepository.DEFAULT_CSRF_COOKIE_NAME).getValue();
webDriver.get(baseUrl + "/login");
String csrf2 = webDriver.manage().getCookieNamed(CookieBasedCsrfTokenRepository.DEFAULT_CSRF_COOKIE_NAME).getValue();
assertNotEquals(csrf1, csrf2);
}
代码示例来源:origin: spring-projects/spring-security
@Test
public void defaultLoginPageWithSingleClientRegistrationThenRedirect() {
this.spring.register(OAuth2LoginWithSingleClientRegistrations.class).autowire();
WebTestClient webTestClient = WebTestClientBuilder
.bindToWebFilters(new GitHubWebFilter(), this.springSecurity)
.build();
WebDriver driver = WebTestClientHtmlUnitDriverBuilder
.webTestClientSetup(webTestClient)
.build();
driver.get("http://localhost/");
assertThat(driver.getCurrentUrl()).startsWith("https://github.com/login/oauth/authorize");
}
代码示例来源:origin: cloudfoundry/uaa
@Before
@After
public void logout_and_clear_cookies() {
try {
webDriver.get(baseUrl + "/logout.do");
}catch (org.openqa.selenium.TimeoutException x) {
//try again - this should not be happening - 20 second timeouts
webDriver.get(baseUrl + "/logout.do");
}
webDriver.get(appUrl+"/j_spring_security_logout");
webDriver.manage().deleteAllCookies();
}
代码示例来源:origin: cloudfoundry/uaa
public void performLogin(String idpZoneId, String idpZoneUserEmail, String idpZoneUrl, IdentityZone spZone, String spZoneUrl, SamlIdentityProviderDefinition samlIdentityProviderDefinition) {
webDriver.get(baseUrl + "/logout.do");
webDriver.get(spZoneUrl + "/logout.do");
webDriver.get(idpZoneUrl+ "/logout.do");
webDriver.get(spZoneUrl + "/");
assertEquals(spZone.getName(), webDriver.getTitle());
Cookie beforeLogin = webDriver.manage().getCookieNamed("JSESSIONID");
assertNotNull(beforeLogin);
assertNotNull(beforeLogin.getValue());
assertNotNull(element);
element.click();
try {
webDriver.findElement(By.xpath("//h1[contains(text(), 'Welcome to The Twiglet Zone[" + idpZoneId + "]!')]"));
webDriver.findElement(By.name("username")).clear();
webDriver.findElement(By.name("username")).sendKeys(idpZoneUserEmail);
webDriver.findElement(By.name("password")).sendKeys("secr3T");
webDriver.findElement(By.xpath("//input[@value='Sign in']")).click();
assertThat(webDriver.findElement(By.cssSelector("h1")).getText(), containsString("Where to?"));
Cookie afterLogin = webDriver.manage().getCookieNamed("JSESSIONID");
assertNotNull(afterLogin);
assertNotNull(afterLogin.getValue());
代码示例来源:origin: cloudfoundry/uaa
private void login(IdentityProvider<SamlIdentityProviderDefinition> provider) {
webDriver.get(baseUrl + "/login");
Assert.assertEquals("Cloud Foundry", webDriver.getTitle());
webDriver.findElement(By.xpath("//a[text()='" + provider.getConfig().getLinkText() + "']")).click();
webDriver.findElement(By.xpath("//h2[contains(text(), 'Enter your username and password')]"));
webDriver.findElement(By.name("username")).clear();
webDriver.findElement(By.name("username")).sendKeys(testAccounts.getUserName());
webDriver.findElement(By.name("password")).sendKeys(testAccounts.getPassword());
webDriver.findElement(By.xpath("//input[@value='Login']")).click();
}
}
代码示例来源:origin: cloudfoundry/uaa
private void signIn(String userName, String password) {
webDriver.get(baseUrl + "/logout.do");
webDriver.get(baseUrl + "/login");
webDriver.findElement(By.name("username")).sendKeys(userName);
webDriver.findElement(By.name("password")).sendKeys(password);
webDriver.findElement(By.xpath("//input[@value='Sign in']")).click();
assertThat(webDriver.findElement(By.cssSelector("h1")).getText(), containsString("Where to?"));
}
}
代码示例来源:origin: code4craft/webmagic
webDriver.get(request.getUrl());
try {
Thread.sleep(sleepTime);
e.printStackTrace();
WebDriver.Options manage = webDriver.manage();
Site site = task.getSite();
if (site.getCookies() != null) {
WebElement webElement = webDriver.findElement(By.xpath("/html"));
String content = webElement.getAttribute("outerHTML");
Page page = new Page();
代码示例来源:origin: cloudfoundry/uaa
@Test
public void testFrameReportsChangedWhenDifferentUser_whenLoggedOut() throws UnsupportedEncodingException, InterruptedException {
webDriver.get(testPage);
webDriver.findElement(By.id("differentUser")).click();
assertMessage("changed");
}
代码示例来源:origin: juzu/juzu
@Test
@RunAsClient
public void test() throws Exception {
driver.get(applicationURL().toString());
System.out.println(driver.getPageSource());
WebDriverWait wait = new WebDriverWait(driver, 5);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("/html[@bar]")));
WebElement elt = driver.findElement(By.tagName("html"));
assertEquals("<bar>foo_value</bar>", elt.getAttribute("bar"));
}
}
内容来源于网络,如有侵权,请联系作者删除!