26 – Element Handling in Selenium
Selenium Class 26: Handling Elements in Selenium
Selenium WebDriver API Commands Continuation:
iv) Verification Commands on Web Elements
14) isDisplayed() command is applicable on all the web elements
15) isEnabled() command is applicable on all the web elements
16) isSelected() command is applicable on Radio Buttons and Check boxes only
14) isDisplayed()
Description:
It checks weather an element is displayed/visable or not in the current web page
Syntax:
boolean variableName = driverObject.WebDriverCommand/findElement(By.ElementLocator(“locarValue”)).WebDriverCommand/isDisplayed();
Example:
driver.get(“http://www.google.com”);
Thread.sleep(2000);
boolean linkPresent = driver.findElement(By.linkText(“Gmail”)).isDisplayed();
System.out.println(linkPresent);
………………………………………………
driver.get(“http://www.google.com”);
Thread.sleep(2000);
boolean linkPresent = driver.findElement(By.linkText(“Yahoo”)).isDisplayed();
System.out.println(linkPresent);
15) isEnabled()
Description:
It checks weather an element is enabled or not?
Syntax:
boolean variableName = driverObject.WebDriverCommand/findElement(By.ElementLocator(“locarValue”)).WebDriverCommand/isEnabled();
Example:
driver.get(“http://www.google.com”);
Thread.sleep(2000);
boolean linkStatus = driver.findElement(By.linkText(“Gmail”)).isEnabled();
System.out.println(linkStatus);
………………………………………………
Button – External Operation (Click) – Internal Operation (Submits)
Link – External Operation (Click) – Internal Operation (Redierects…)
Radio Button External Operation (Click) – Internal Operation (Selects)
Checkbox External Operation (Click) – Internal Operation (Selects/Checks)
16) isSelected()
It checks weather an element (Radio Button or Checkbox) is selected or not in the current web page
Syntax:
boolean variableName = driverObject.WebDriverCommand/findElement(By.ElementLocator(“locarValue”)).WebDriverCommand/isSelected();
Example:
//Instantiate MS Edge Browser driver
System.setProperty(“webdriver.chrome.driver”, “E:/chromedriver.exe”);
//Create Edge Browser Driver for WebDriver interface
WebDriver driver= new ChromeDriver();
driver.manage().window().maximize();
//Launch gcrShop Admin Home page
driver.get(“http://www.gcrit.com/build3/create_account.php?osCsid=4uc26s88u88n2h22efs7qm8qi7”);
boolean buttonStatus= driver.findElement(By.name(“gender”)).isSelected();
System.out.println(buttonStatus);//false
WebElement checkBox = driver.findElement(By.name(“newsletter”));
System.out.println(checkBox.isSelected());//false
Thread.sleep(2000);
checkBox.click();
System.out.println(checkBox.isSelected());//true
Thread.sleep(2000);
checkBox.click();
System.out.println(checkBox.isSelected());//false
Element Handling in Selenium
i) Web Elements
ii) Element Locators
iii) Selenium WebDriver Commands
iv) Java Programming (Java Standard Edition / Core Java)
i) Web Elements
Browser,
Page,
………………..
Link,
Edit Box,
Text Box,
Text Area, Error Message and Popup Window
Image, Image Button and Image Link
Radio Button,
Checkbox,
Drop down box,
List box,
Combo box,
Web Table/HTML Table
Frame etc…
………………………………………………
ii) Element Locators
1) id
2) name
3) className
4) tagName
5) linkText
6) partialLinkText
7) cssSelector
8) xpath
………………………………………………
iii) Selenium WebDriver Commands
a) Browser Regular Commands
b) Browser Navigation Commands
c) Commands on Web Elements
d) Verification Commands
Etc…
a) Browser Regular Commands
1) get()
2) getTitle()
3) getCurrentUrl()
4) getWindowHandle()
5) close()
6) quit()
b) Browser Navigation Commands
1) navigate().to()
2) navigate().back()
3) navigate().forward()
4) navigate().refresh()
c) Commands on Web Elements
1) findElement()
2) findElements()
3) sendKeys()
4) click()
5) clear()
6) getText()
7) getAttibute(“Arg…”)
d) Verification Commands
1) isDisplayed()
2) isEnabled()
3) isSelected()
………………………………………………
iv) Java Programming (Java Standard Edition / Core Java)
1) Comments
2) Data Types
3) Modifiers
4) Variables
5) Operators
6) Java Control Flow Statements
a) Conditional Statements/Decision Making Statements
b) Loop Statements
c) Branching Statements
7) String Handling
8) Array, ArrayList
9) IO Operations (includes File handling)
10) Java Methods
a) Built-in Methods
b) User defined Methods
11) Exception Handling
12) Java OOPS
a) Inheritance
b) Polymorphism
c) Abstraction
d) Encapsulation
1) Handling Browser
Manual Operations:
- Lunch the Browser
- Navigate to a specified url
- Return Browser Title
- Return Browser Url
- Return Page Source
- Return Browser Window Handle
- Closed Focused Browser
- Close all Browser that opened by WebDriver during execution
………………………… - Navigate to another url
- Navigate back to previous url
- Navigate Forward
- Navigate Refresh (Refresh the Browser)
………………………. - Maximize Browser Window
- Maximize Browser Window
- Full Screen Browser Window
………………………………………………………………………..