-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImage.java
More file actions
106 lines (79 loc) · 3.7 KB
/
Image.java
File metadata and controls
106 lines (79 loc) · 3.7 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package elements;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.concurrent.TimeUnit;
/**
* Created by jfarrier on 17/10/2016.
*/
public class Image {
public static void main(String[] args) {
/*
In HTML, images are defined with the <img> tag.
The <img> tag is empty, it contains attributes only, and does not have a closing tag.
The src attribute specifies the URL (web address) of the image:
For more information check - http://www.w3schools.com/tags/tag_img.asp and/or http://www.w3schools.com/html/html_images.asp
Additionally inputs may also be images.
See - http://www.w3schools.com/tags/att_input_src.asp
*/
//FirefoxDriver webdriver = new FirefoxDriver();
System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
WebDriver webdriver = new ChromeDriver();
webdriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
webdriver.navigate().to("http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_input_src");
webdriver.switchTo().frame("iframeResult");
WebElement imageElement = webdriver.findElement(By.xpath("//input[@type='image']"));
System.out.println("getAttribute = " + imageElement.getAttribute("value"));
System.out.println("getText = " + imageElement.getText());
System.out.println("getTagName = " + imageElement.getTagName());
System.out.println("getSize = " + imageElement.getSize().getHeight());
System.out.println("getLocation = " + imageElement.getLocation().x);
System.out.println("isDisplayed = " + imageElement.isDisplayed());
System.out.println("isEnabled = " + imageElement.isEnabled());
System.out.println("isSelected = " + imageElement.isSelected());
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
imageElement.click();
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
webdriver.navigate().to("http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_input_src");
webdriver.switchTo().frame("iframeResult");
imageElement = webdriver.findElement(By.xpath("//input[@type='image']"));
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
imageElement.submit();
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
webdriver.navigate().to("http://www.w3schools.com/html/tryit.asp?filename=tryhtml_images_mountain");
webdriver.switchTo().frame("iframeResult");
imageElement = webdriver.findElement(By.tagName("img"));
System.out.println("getAttribute = " + imageElement.getAttribute("src"));
System.out.println("getText = " + imageElement.getText());
System.out.println("getTagName = " + imageElement.getTagName());
System.out.println("getSize = " + imageElement.getSize().getHeight());
System.out.println("getLocation = " + imageElement.getLocation().x);
System.out.println("isDisplayed = " + imageElement.isDisplayed());
System.out.println("isEnabled = " + imageElement.isEnabled());
System.out.println("isSelected = " + imageElement.isSelected());
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
imageElement.click();
webdriver.quit();
}
}