Some tips about Selenium UI testing

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;

转载于:https://my.oschina.net/u/942203/blog/845320

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值