多选框
package com.test.selenium;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class ActionSelenium {
public WebDriver driver;
public void InitDriver(){
System.setProperty("webdriver.firefox.bin","C:\\Program Files\\Mozilla Firefox\\firefox.exe");
driver = new FirefoxDriver();
driver.navigate().to("https://www.imooc.com/user/newlogin");
driver.manage().window().maximize();
}
public void inputBox(){
try{
Thread.sleep(2000);
}catch(InterruptedException e){
e.printStackTrace();
}
driver.findElement(By.name("email")).sendKeys("895236987@qq.com");
driver.findElement(By.name("password")).sendKeys("sder");
try{
Thread.sleep(4000);
}catch(InterruptedException e){
e.printStackTrace();
}
}
public void radioBox(){
driver.get("https://www.imooc.com/user/setprofile");
driver.findElement(By.className("pull-right")).click();
List<WebElement> elements = driver.findElements(By.xpath(".//*[@id='profile']/div[4]/div/label//input"));
System.out.println(elements.size());
try{
Thread.sleep(2000);
}catch(InterruptedException e){
e.printStackTrace();
}
for(WebElement radio:elements){
boolean flag = radio.isSelected();
if(flag==false){
radio.click();
break;
}else{
System.out.println("选中了");
}
}
}
/**
* 复选框
* */
public void checkBox(){
WebElement check = driver.findElement(By.id("auto-signin"));
System.out.println("是否选中了呢?" + check.isSelected());
System.out.println("是否有效?" + check.isEnabled());
try{
Thread.sleep(3000);
}catch(InterruptedException e){
e.printStackTrace();
}
check.click();
}
public void button(){
WebElement login = driver.findElement(By.className("moco-btn"));
System.out.println(login.isEnabled());
System.out.println(login.getAttribute("value"));
login.click();
}
public void webForm(){
driver.get("XXXXX");
driver.findElement(By.id("signup-form")).submit();
}
public void upHeader(){
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
driver.get("https://www.imooc.com/user/setbindsns");
driver.findElement(By.className("js-avator-link")).click();
driver.findElement(By.id("upload")).sendKeys("C:\\Users\\Public\\Pictures\\Sample Pictures\\logd.png");
}
public static void main(String[] args) {
ActionSelenium as = new ActionSelenium();
as.InitDriver();
as.inputBox();
as.button();
as.upHeader();
}
}