forked from easonhan007/webdriver_guide
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStatus.java
More file actions
53 lines (40 loc) · 1.58 KB
/
Status.java
File metadata and controls
53 lines (40 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import java.io.File;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class Status {
public static void main(String[] args) throws InterruptedException {
WebDriver dr = new ChromeDriver();
File file = new File("src/status.html");
String filePath = "file:///" + file.getAbsolutePath();
System.out.printf("now accesss %s \n", filePath);
dr.get(filePath);
Thread.sleep(1000);
WebElement textField = dr.findElement(By.name("user"));
System.out.println(textField.isEnabled());
// 直接用isEnabled方法去判断该button的话返回的会是true
// 这是因为button是使用css方法去disabled的,并不是真正的disable
// 这时候需要判断其class里是否有disabled这值来判断其是否处于disable状态
System.out.println(dr.findElement(By.className("btn")).isEnabled());
// 隐藏掉textField
// 判断其是否显示
((JavascriptExecutor)dr).executeScript("$(arguments[0]).hide()", textField);
System.out.println(textField.isDisplayed());
// 使用click方法选择raido
WebElement radio = dr.findElement(By.name("radio"));
radio.click();
System.out.println(radio.isSelected());
try{
dr.findElement(By.id("none"));
} catch(NoSuchElementException e){
System.out.println("element does not exist");
}
Thread.sleep(1000);
System.out.println("browser will be close");
dr.quit();
}
}