1. 怎样验证“no scroll bar exist” 或者 “ no view all button exist” ?
SeleniumUtil.runJs(driver, "var obj = arguments[0]; obj.scrollTop = 1", new Object[] {rightTable});
Assert.assertTrue((long)(SeleniumUtil.runJs(driver, "var obj = arguments[0]; return obj.scrollTop", new Object[] {rightTable})) > 0, "There're not any scroll bar");
Method 1 :
Assert.assertTrue(!SeleniumUtil.isElementPresent(driver, By.cssSelector("button.action-done")), "errormessage");
Method 2 :
try {
List<WebElement> searchResultList = screenerPage.getSearchResultRowsInAdvancedSearch();
Assert.fail("the above element should not be visible");
}catch (Exception ex) {
//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 ?
- In order to click the element ,change it to visible firstly.When we operate manually,actually,we first move the mouse to the row ,and then click the element.
- So, when automate the click action,we also need to move the mouse to the row firstly,then the element will be visible,this is the trick.
- Hover to the row of DDL, move mouse to the front of the row, then click the DDL would work.
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;