161718192021222324
System.out.printf("title of current page is %s\n", dr.getTitle()); System.out.printf("url of current page is %s\n", dr.getCurrentUrl()); System.out.println("browser will be close"); dr.quit(); } }
282930313233343536
WebElement current_page = dr.findElement(By.className("pagination")).findElement(By.className("active")); System.out.printf("Current page is %s\n", current_page.getText()); Thread.sleep(1000); System.out.println("browser will be close"); dr.quit(); } }
272829303132333435
// 获取该链接的text System.out.println(link.getText()); Thread.sleep(1000); System.out.println("browser will be close"); dr.quit(); } }
Alert alert = dr.switchTo().alert(); alert.accept(); Thread.sleep(1000); System.out.println("browser will be close"); dr.quit(); } }
424344454647484950
List<WebElement> allCheckboxes = dr.findElements(By.cssSelector("input[type=checkbox]")); allCheckboxes.get(allCheckboxes.size() - 1).click(); Thread.sleep(1000); System.out.println("browser will be close"); dr.quit(); } }
111213141516171819
System.out.println("maximize browser"); dr.manage().window().maximize(); Thread.sleep(2000); System.out.println("browser will be close"); dr.quit(); } }
505152535455565758
// by xpath dr.findElement(By.xpath("/html/body/form/div[3]/div/label/input")).click(); Thread.sleep(1000); System.out.println("browser will be close"); dr.quit(); } }
293031323334353637
// SendKeys to A dr.findElement(By.id("A")).sendKeys(Keys.chord("watir webdriver is better than selenium webdriver")); Thread.sleep(1000); System.out.println("browser will be close"); dr.quit(); } }
454647484950515253
System.out.println("element does not exist"); } Thread.sleep(1000); System.out.println("browser will be close"); dr.quit(); } }
4041424344454647
WebElement link = dr.findElement(By.id("myModal")).findElement(By.id("click")); ((JavascriptExecutor)dr).executeScript("$(arguments[0]).click()", link); Thread.sleep(1000); System.out.println("browser will be close"); dr.quit(); } }