1. 怎样验证“no scroll bar exist” 或者 “ no view all button exist” ?css
SeleniumUtil.runJs(driver, "var obj = arguments[0]; obj.scrollTop = 1", new Object[] {rightTable});this
Assert.assertTrue((long)(SeleniumUtil.runJs(driver, "var obj = arguments[0]; return obj.scrollTop", new Object[] {rightTable})) > 0, "There're not any scroll bar");orm
Method 1 : ip
Assert.assertTrue(!SeleniumUtil.isElementPresent(driver, By.cssSelector("button.action-done")), "errormessage");element
Method 2 : get
try {input
List<WebElement> searchResultList = screenerPage.getSearchResultRowsInAdvancedSearch();it
Assert.fail("the above element should not be visible");io
}catch (Exception ex) {form
//Go to next step
}
2. 键盘操做怎么automated, 例如ESC键, 向上向下键 ?
Actions action = new Actions(driver);
action.keyDown(Keys.valueOf("p")).keyUp(Keys.valueOf("p")).perform();
3. 怎样定义使用一个List类的 MAP ?
Map<String, List<WebElement>> map = new HashMap<String, List<WebElement>>();
map.put("firstname", list);
4. 怎样获取hidden element的Text?
Cannot get text of hidden element by element.gettext(), but this would works well:
WebElement element = driver.findElement(By.cssSelector("input #username"));
String actualDataPointName = (String) ((JavascriptExecutor) driver).executeScript(
"return jQuery(arguments[0]).text();", element);
5. How to click element under one hidden element ?
WebElement theRow = this.findBlankBenchmarkRow();
Assert.assertNotSame(theRow, null, "Should find out a blank benchmark row.");
Actions action = new Actions(driver);
System.out.println("Row size : "+theRow.getSize());
System.out.println(("X offset : "+(theRow.getSize().width)/100));
System.out.println(("Y offset : "+(theRow.getSize().height)/2));
int locx=0;
int locy=0;
locx=(theRow.getSize().width)/100;
locy=(theRow.getSize().height)/2;
action.moveToElement(theRow, locx, locy).perform();
SeleniumUtil.sleep(2);
WebElement theDDL = theRow.findElement(By.cssSelector("td div.dash-bmk-ddl"));
return theDDL;