1. 输入框(text field or textarea)
1 WebElement we = driver.findElement(By.id("id")); 2 //将输入框清空 3 we.clear(); 4 // 在输入框中输入内容 5 we.sendKeys(“test”); 6 // 获取输入框的文本内容, 取得就是 value 属性的值 7 element.getAttribute("value");
2. 下拉选择框(select)
1 // 找到下拉选择框的元素 2 Select select = new Select(driver.findElement(By.id("id"))); 3 // 选择对应的选择项 4 select.selectByVisibleText(“ 北京市 ”); // 通过可见文本去选择 5 select.selectByValue(“beijing”); // 通过 html 标签中的 value 属性值去选择 6 select.selectByIndex(1); // 通过 index(索引从0开始)选择 7 //