<div> <p>链接 link</p> <a href="www.cnblogs.com/tankxiao">小坦克</a> </div>
// 找到链接元素
WebElement link1 = driver.findElement(By.linkText("小坦克"));
WebElement link11 = driver.findElement(By.partialLinkText("坦克"));
// 点击链接
link1.click();
<div> <p>输入框 testbox</p> <input type="text" id="usernameid" value="username" /> </div>
// 找到元素
WebElement element = driver.findElement(By.id("usernameid"));
// 在输入框中输入内容
element.sendKeys("test111111");
// 清空输入框
element.clear();
// 获取输入框的内容
element.getAttribute("value");
<div> <p>按钮 button</p> <input type="button" value="添加" id="proAddItem_0" /> </div>
//找到按钮元素 String xpath="//input[@value='添加']"; WebElement addButton = driver.findElement(By.xpath(xpath)); // 点击按钮 addButton.click(); // 判断按钮是否enable addButton.isEnabled();
<div> <p>下拉选择框框 Select</p> <select id="proAddItem_kind" name="kind"> <option value="1">电脑硬件</option> <option value="2">房产</option> <option value="18">种类AA</option> <option value="19">种类BB</option> <option value="20">种类BB</option> <option value="21">种类CC</option> </select> </div>
// 找到元素
Select select = new Select(driver.findElement(By.id("proAddItem_kind")));
// 选择对应的选择项, index 从0开始的
select.selectByIndex(2);
select.selectByValue("18");
select.selectByVisibleText("种类AA");
// 获取所有的选项
List<WebElement> options = select.getOptions();
for (WebElement webElement : options) {
System.out.println(webElement.getText());
}
<div> <p>单选项 Radio Button</p> <input type="radio" value="Apple" name="fruit>" />Apple <input type="radio" value="Pear" name="fruit>" />Pear <input type="radio" value="Banana" name="fruit>" />Banana <input type="radio" value="Orange" name="fruit>" />Orange </div>
// 找到单选框元素
String xpath="//input[@type='radio'][@value='Apple']";
WebElement apple = driver.findElement(By.xpath(xpath));
//选择某个单选框
apple.click();
//判断某个单选框是否已经被选择
boolean isAppleSelect = apple.isSelected();
// 获取元素属性
apple.getAttribute("value");
<div> <p>多选项 checkbox</p> <input type="checkbox" value="Apple" name="fruit>" />Apple <input type="checkbox" value="Pear" name="fruit>" />Pear <input type="checkbox" value="Banana" name="fruit>" />Banana <input type="checkbox" value="Orange" name="fruit>" />Orange </div>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有