java脚本实现selenium架构下的复选框、上传文件的操作
driver.get("http://home.51cto.com/user/register?reback=http%253A%252F%252Fblog.51cto.com%252Flisea%252Fp2");
element = driver.findElement(By.name("checkbox"));
System.out.println("单选框"+ element.getAttribute("checked"));
System.out.println("单选框"+ element.getAttribute("name"));
element.click();
System.out.println("单选框"+ element.isSelected());
System.out.println("是否可编辑"+ element.isEnabled());
element.click();
总结:选择或取消选择,用 element.click();,不用 element.clear();。用clear会报错
//点浏览文件
element = driver.findElement(By.id("AddFiles_myFile"));
System.out.println("点浏览文件"+ element.getText());
String file = null;
file = "C:\\\\Users\\\\THINK\\\\Desktop\\\\Selenium8种定位方式.rar";
element.sendKeys(file);
总结:上传文件用 element.sendKeys(file);不用管弹出的选择文件对话框