Skip to content

Commit da6d250

Browse files
Naveen KhuntetaNaveen Khunteta
authored andcommitted
code for visibility element session
1 parent daa6edc commit da6d250

File tree

5 files changed

+138
-0
lines changed

5 files changed

+138
-0
lines changed
2.39 KB
Binary file not shown.
2.33 KB
Binary file not shown.

bin/SeleniumSessions/element.png

40.6 KB
Loading
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package SeleniumSessions;
2+
3+
import java.util.concurrent.TimeUnit;
4+
5+
import org.openqa.selenium.By;
6+
import org.openqa.selenium.WebDriver;
7+
import org.openqa.selenium.chrome.ChromeDriver;
8+
9+
public class CheckVisibilityElement {
10+
11+
/**
12+
*
13+
* Learn difference between:
14+
15+
isDisplayed() v/s isEnabled() v/s isSelected()
16+
17+
Notes:
18+
• isDisplayed() is the method used to verify presence of a web element within the webpage.
19+
The method returns a “true” value if the specified web element is present on the web page and a “false” value if the web element is not present on the web page.
20+
• isDisplayed() is capable to check for the presence of all kinds of web elements available.
21+
• isEnabled() is the method used to verify if the web element is enabled or disabled within the webpage.
22+
• isEnabled() is primarily used with buttons.
23+
• isSelected() is the method used to verify if the web element is selected or not. isSelected()
24+
method is pre-dominantly used with radio buttons, dropdowns and checkboxes.
25+
26+
*
27+
*/
28+
29+
30+
31+
32+
public static void main(String[] args) throws InterruptedException {
33+
34+
System.setProperty("webdriver.chrome.driver", "/Users/naveenkhunteta/Downloads/chromedriver");
35+
36+
WebDriver driver = new ChromeDriver(); // launch chrome
37+
38+
driver.manage().window().maximize(); // maximize window
39+
driver.manage().deleteAllCookies(); // delete all the cookies
40+
41+
// dynamic wait
42+
driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);
43+
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
44+
45+
driver.get("https://www.freecrm.com/register/"); // enter URL
46+
47+
//isDiplayed() Method:
48+
boolean b1 = driver.findElement(By.id("submitButton")).isDisplayed();
49+
System.out.println(b1); //true
50+
51+
//before selecting checkbox --I agree
52+
//isEnabled() method:
53+
boolean b2 = driver.findElement(By.id("submitButton")).isEnabled();
54+
System.out.println(b2); //false
55+
56+
//lets make submit button enabled:
57+
driver.findElement(By.name("agreeTerms")).click(); //check I Agree checkbox
58+
59+
//after selecting checkbox --I agree
60+
//isEnabled() method:
61+
boolean b3 = driver.findElement(By.id("submitButton")).isEnabled();
62+
System.out.println(b3); //true
63+
64+
65+
//isSelected() method: only applicable for checkbox, dropdown, radiobutton
66+
boolean flag1 = driver.findElement(By.name("agreeTerms")).isSelected();
67+
System.out.println(flag1); //true
68+
69+
//de-select the checkbox-- I Agree
70+
driver.findElement(By.name("agreeTerms")).click(); //check I Agree checkbox
71+
72+
boolean flag2 = driver.findElement(By.name("agreeTerms")).isSelected();
73+
System.out.println(flag2); //false
74+
75+
76+
77+
78+
}
79+
80+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package SeleniumSessions;
2+
3+
import java.util.concurrent.TimeUnit;
4+
5+
import org.openqa.selenium.By;
6+
import org.openqa.selenium.WebDriver;
7+
import org.openqa.selenium.chrome.ChromeDriver;
8+
9+
public class ElementVisibilityTest {
10+
11+
public static void main(String[] args) {
12+
13+
14+
System.setProperty("webdriver.chrome.driver", "/Users/naveenkhunteta/Downloads/chromedriver");
15+
16+
WebDriver driver = new ChromeDriver(); // launch chrome
17+
18+
driver.manage().window().maximize(); // maximize window
19+
driver.manage().deleteAllCookies(); // delete all the cookies
20+
21+
// dynamic wait
22+
driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);
23+
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
24+
25+
driver.get("https://www.freecrm.com/register/"); // enter URL
26+
27+
//1. isDisplayed() method: applicanle for all the elements
28+
boolean b1 = driver.findElement(By.id("submitButton")).isDisplayed(); //for submit button
29+
System.out.println(b1); //true
30+
31+
//2. isEnabled() method:
32+
boolean b2 = driver.findElement(By.id("submitButton")).isEnabled();
33+
System.out.println(b2);//false
34+
35+
//select I Agree checkbox:
36+
driver.findElement(By.name("agreeTerms")).click(); //--submit button is enabled now
37+
boolean b3 = driver.findElement(By.id("submitButton")).isEnabled();
38+
System.out.println(b3);//true
39+
40+
41+
//3. isSelected() method: only applicable for checkbox, dropdown, radiobutton
42+
boolean b4 = driver.findElement(By.name("agreeTerms")).isSelected();
43+
System.out.println(b4);//true
44+
45+
46+
//de-select the checkbox:
47+
driver.findElement(By.name("agreeTerms")).click();
48+
boolean b5 = driver.findElement(By.name("agreeTerms")).isSelected();
49+
System.out.println(b5);//false
50+
51+
52+
53+
54+
55+
56+
}
57+
58+
}

0 commit comments

Comments
 (0)