Auto-Test 要点纪录(一)

1,select下拉框类型

使用工具可以看到html对应标签为<select>这类标签才是真正的下拉框类型就需要对应的方法,不能但看页面上的效果,有的做成了效果但其实不是select类型即不能使用select相应方法

Select selectState = new Select(driver.findElement(By
                    .id("billing_state_id")));
            selectState.selectByValue("12");

2,刷新页面

String script = "document.location.reload()";
            ((JavascriptExecutor) driver).executeScript(script);

3,截获文本内容,多见于提示信息显示速即被hide效果

            WebElement hiddenDiv = driver.findElement(By.id("notice"));
            String script = "return document.getElementById('notice').innerHTML";
            String currentText = (String) ((JavascriptExecutor) driver)
                    .executeScript(script, hiddenDiv);
            log.info("the text is " + currentText);

4,在查找元素时遵循的原则是如果元素的id或者class唯一显著那么可以直接访问id或者class而不要执迷于css或者xpath这样往往查找耗时而且容易找不到

原文地址:https://www.cnblogs.com/lisa090818/p/3183653.html