Android apps to use in appium android test examples

Breaking

Thursday, May 31, 2018

Element Handling inwards Selenium

 Web Elements too Operations on Web Elements Element Handling inward Selenium
Element Handling inward Selenium

I) Web Elements too Operations on Web Elements
II) Elements Locators inward Selenium
III) Elements Handling inward Selenium
-------------------------------
I) Web Elements too Operations on Web Elements

i) Web Elements

Browser,
Page
-------------------
Edit Box,
Text Box,
Link,
Button,
Image, Image Link, Image Button
Text Area, Error Message
Check Box,
Radio Button,
Drop Down Box
List Box
Combo Box (Edit Box too Drop Down)
Web Table/HTML Table
Frame Etc...
-------------------------------
ii) Operations on Web Elements

1) Browser

> Launch Browser
> Navigate to item URL
> Close Browser
> Close all Opened Browsers
-------------------------------
> Navigate From ane url to another
> Navigate Back
> Navigate Forward
> Minimize the Browser
> Maximize the Browser
> Full Screen the Browser
> Refresh the Browser
> Capture the Browser URL
> Select Home Page
-------------------------------
2) Page

> Get Page Title
> Get Page Source
> Get Page URL
-------------------------------
3) Operations on Edit Box

> Check the Existence of Edit Box
> Check the Enabled Status
> Enter a Value
> Edit the Existing value
> Clear the Value
> Get / Return the Value
-------------------------------
4) Operations on Link

Text Link...
Image Link...

Text Link...
 Internal Link
 External Link
-------------------------------
> Check the Existence of the Link
> Check Enabled Status
> Click
> Return Link Name
-------------------------------
5) Image 

a) General Image - 
 Check the Existence of the Image
 Check the Enabled Status of the Image
 Return Image Name etc...

b) Image Link
 > Check the Existence of the Image Link
 > Check Enabled Status
 > Click
 > Return Image Link Name
c) Image Button
 > Check the Existence of the Image Button
 > Check the Enabled condition of the Image Button
 > Click/Submit
 > Return Image Button Name....
-------------------------------
6) Operations on Check box

> Check the Existence of the Check box
> Check the Enabled of the Check box
> Check the Selected of the Check box

> Select
> Unselect
-------------------------------
7) Operations on Button

> Check the Existence of the button
> Check the Enabled Status
> Click
> Return Button Name...
-------------------------------
8) Operations on Radio Button

> Check the Existence of the Radio Button
> Check the Enabled Status of the Radio Button
> Check the selected Status of the Radio Button
> Select
-------------------------------
9) Operations on Drop downwardly Box

> Check the Existence of the Drop downwardly Box
> Check the Enabled Status of the Drop downwardly Box
> Select an Item
> Return Items Count...
-------------------------------
10) Operations on List Box

> Check the Existence of the List Box
> Check the Enabled Status of the List Box
> Select ane or to a greater extent than items
> Return Items Count...
-------------------------------
11) Operations on Combo Box

> Check the Existence of the Combo Box
> Check the Enabled Status of the Combo Box
> Select an Item..
> Return Items Count....
> Enter a Value...
-------------------------------
12) Operations on Web Table or HTML Table

> Check the Existence of the Web Table
> Return a Cell Value...
> Return Rows Count
> Return Column Count...
-------------------------------
13) Operations on Frame

> Swith from Top Window to a Frame
> Swith to default content from a Frame
-------------------------------
II) Elements Locators inward Selenium

1) id 

Syntax:

driverObject.WebDriverCommand(By.ElementLocator/id("Locator value"));

Example:
driver.findElement(By.id("Email"));
driver.findElement(By.id("Email")).sendKeys("India123");
-------------------------------
driver - Browser Object
findElement - WebDriver Command - to position the chemical cistron based on given locator...
By - Predefined Class
id - Locator
Email - Locato value 
sendkeys - WebDriver Command - To perform performance on the Element
India123 - Input Data
-------------------------------
2nd Syntax:

WebElement elementName = driverObject.WebDriverCommand(By.ElementLocator("Locatot value"));

elementName.WebDriverCommand();

Example:
WebDriver driver = novel FirefoxDriver();
driver.get("https://www.gmail.com");
WebElement ebox = driver.findElement(By.id("Email"));
ebox.sendKeys("VijayB");
Thread.sleep(5000);
ebox.clear();
Thread.sleep(5000);
ebox.sendKeys("BVijayBangalore");
-------------------------------
Note: Whenever nosotros desire perform multiple operatons on whatsoever Element thus select this sec Syntax...
-------------------------------
2) name

Syntax:
driverObject.WebDriverCommand(By.ElementLocator/name("Locatot value"));

Example:
driver.findElement(By.name("username")).sendKeys("Pavani123");
-------------------------------
2nd Sysntax:

WebElement Username = driver.findElement(By.name("username"));
Username.sendKeys("123Pavani");
-------------------------------
3) className

driver.get("http://www.google.com");
driver.findElement(By.className("gb_P")).click();
-------------------------------
4) tagName

driver.get("file:///C:/Users/gcreddy/Desktop/HTMLExamples/LoginPage.html");
driver.findElement(By.tagName("input")).sendKeys("Jyothi");
-------------------------------
5) linkText

Sytax:

driverObject.WebDriverCommand(By.ElementLocator/linkText("Locatot value"));

Example:
driver.get("https://www.google.co.in");
driver.findElement(By.linkText("Images")).click();
-------------------------------
6) partialLinkText

driver.get("https://www.google.co.in");
driver.findElement(By.partialLinkText("a")).click();
-------------------------------
7) cssSelector 

Sysntax:
driverObject.WebDriverCommand(By.ElementLocator/cssSelector("cssSelector Value"));

Example:
driver.get("https://www.google.co.in");
driver.findElement(By.cssSelector(".gb_P")).click();
-------------------------------
8) xpath

xpath is defined equally XML path, It is a syntax for identifying whatsoever chemical cistron on the spider web page using XML path expression.
xpath is used to discovery the place of whatsoever chemical cistron on a spider web page using HTML DOM structure.

Syntax:
driverObject.WebDriverCommand(By.ElementLocator/xpath("xpath Value"));

Example:
driver.get("https://www.google.co.in");
driver.findElement(By.xpath(".//*[@id='gbw']/div/div/div[1]/div[1]/a")).click();
-------------------------------
III) Elements Handling inward Selenium

1) Handling Browser

> Launch Browser (Create browser driver instance...)
> Navigate to specific URL
> Return Current URL
> Return Browser Title
> Return Page Source
> Return Window Handle
> Close Focused Browser
> Close all Browsers that opened past times WebDriver during Execution.
-------------------------------
> Navigate to about other URL
> Navigate dorsum to previous URL
> Navigate Forward
> refresh the Browser
> Minimize the Browser
-------------------------------
Selenium Webdriver Steps:

Example:
WebDriver driver = novel FirefoxDriver();
driver.get("https://www.google.co.in/");
System.out.println(driver.getTitle());

driver.navigate().to("https://in.yahoo.com/");
System.out.println(driver.getTitle());

driver.navigate().back();
System.out.println(driver.getTitle());

driver.navigate().forward();;
System.out.println(driver.getTitle());

driver.close();
-------------------------------
2) Handling Edit Box

> Check Displayed Status
> Check Enabled Status
> Enter about Value
> Return the Value
> Clear the Value
------------------------------------------
Selenium WebDriver Steps:

WebDriver driver = novel FirefoxDriver();
driver.get("https://www.gmail.com/");
boolean displayStatus = driver.findElement(By.id("Email")).isDisplayed();
System.out.println(displayStatus);//true

boolean enabledStatus = driver.findElement(By.id("Email")).isEnabled();
System.out.println(enabledStatus);//true

driver.findElement(By.id("Email")).sendKeys("Vijay321");

String Email = driver.findElement(By.id("Email")).getAttribute("value");
System.out.println(Email);

Thread.sleep(4000);

driver.findElement(By.id("Email")).clear();
//driver.close();
-------------------------------
Note: Whenever you lot desire to perform multiple operations on the same chemical cistron inward a Test Script thus create
WebElement too perform operations ane past times one...

WebDriver driver = novel FirefoxDriver();
driver.get("https://www.gmail.com/");
String EmailValue = "Pavani123@gmail.com";

WebElement electronic mail = driver.findElement(By.id("Email"));

boolean a = email.isDisplayed();
System.out.println(a);

a = email.isEnabled();
System.out.println(a);

email.sendKeys(EmailValue);

String emailAddress = email.getAttribute("value");
System.out.println(emailAddress);

Thread.sleep(5000);

email.clear();

//driver.close();
-------------------------------
3) Handling Text Area, Error Message, Popup window

a) Handling Text Area

Returning the Text....

Example:
WebDriver driver = novel FirefoxDriver();
driver.get("https://www.gmail.com/");
String textArea = driver.findElement(By.tagName("h1")).getText();
System.out.println(textArea);

b) Error Message

driver.findElement(By.id("next")).click();
Thread.sleep(3000);
String error_Message = driver.findElement(By.id("errormsg_0_Email")).getText();
System.out.println(error_Message);

c) Popup window

public degree Class1 {

public static void main(String[] args) throws InterruptedException {
WebDriver driver = novel FirefoxDriver();
driver.get("https://www.gmail.com/");
String textArea = driver.findElement(By.tagName("h1")).getText();
System.out.println(textArea);

driver.findElement(By.id("next")).click();
Thread.sleep(3000);
String error_Message = driver.findElement(By.id("errormsg_0_Email")).getText();
System.out.println(error_Message);

driver.navigate().to("https://mail.rediff.com/cgi-bin/login.cgi");
driver.findElement(By.name("proceed")).click();

Alert popUp = driver.switchTo().alert(); // Switch the driver focus from the spider web page th Popup/Alert message
String errorMessage2 = popUp.getText();
popUp.accept();
driver.findElement(By.id("login1")).sendKeys("Ravindra123@rediffmail.com");
System.out.println(errorMessage2);

driver.close();
-------------------------------
4) Handling Button (Submits)

> Check the Displayed Status
> Check the Enabled Status

> Click

> Return Name of the Object
> Return Type of the Object
-------------------------------
Selenium WebDriver Steps:

public degree Class1 {

public static void main(String[] args) throws InterruptedException {
WebDriver driver = novel FirefoxDriver();
driver.get("https://www.gmail.com/");

boolean displayStatus = driver.findElement(By.id("next")).isDisplayed();
boolean enabledStatus = driver.findElement(By.id("next")).isEnabled();

String typeoftheElement = driver.findElement(By.id("next")).getAttribute("type");
String nameoftheElement = driver.findElement(By.id("next")).getAttribute("value");

System.out.println(displayStatus);//true
System.out.println(enabledStatus);//true
System.out.println(typeoftheElement);//Submit
System.out.println(nameoftheElement);//Next

driver.findElement(By.id("next")).click();
driver.close();
-------------------------------
Create Web Element too acquit multiple operations...

public degree Class1 {

public static void main(String[] args) throws InterruptedException {
WebDriver driver = novel FirefoxDriver();
driver.get("https://www.gmail.com/");
WebElement push clit = driver.findElement(By.id("next"));

boolean displayStatus = button.isDisplayed();
boolean enabledStatus = button.isEnabled();

String typeoftheElement = button.getAttribute("type");
String nameoftheElement = button.getAttribute("value");

System.out.println(displayStatus);//true
System.out.println(enabledStatus);//true
System.out.println(typeoftheElement);//Submit
System.out.println(nameoftheElement);//Next

button.click();
driver.close();
-------------------------------
With Differnt Locators....

//Button alongside id Locator...
driver.findElement(By.id("next")).click();

//Button alongside refer Locator...
driver.findElement(By.name("signIn")).click();

//Button alongside cssSelector Locator...
driver.findElement(By.cssSelector("#next")).click();

//Button alongside xpath Locator...
driver.findElement(By.xpath(".//*[@id='next']")).click();

Note: linkText too partialLinkText locators are non applicable for this element
-------------------------------
5) Handle Link

Types of Links inward the Web (UI pattern indicate of view...)
 i) Text Link (Ex: gmail link inward Google abode page)
 ii) Image Link (Ex: Selenium IDE (Image) Link inward seleniumhq.org abode page)

Note: Redirecting to about other Location / about other Page or about other Application
-------------------------------
Types of Links inward the Web (Functionality Point of view...)
 1) Internal Link (Ex: link inward wikipedia.com)
 * Redirects to about other place or about other page inward the same Application
 2) External Link (Ex: github.com link inward wikipedia.com)
 * Redirects to about other page inward the Another Application
-------------------------------
Broken Links...

Operations on Link

> Check Displayed Status
> Check Enabled Status

> Click 

> Return Link name....
-------------------------------
Selenium WebDriver Steps:

public static void main(String[] args) throws InterruptedException {
WebDriver driver = novel FirefoxDriver();
driver.get("https://www.google.co.in/");
WebElement link = driver.findElement(By.linkText("Gmail"));

boolean displayedStatus = link.isDisplayed();
boolean enabledStatus = link.isEnabled();

String linkName = link.getText();

System.out.println(displayedStatus);//true
System.out.println(enabledStatus);//true
System.out.println(linkName);//Gmail

link.click();
-------------------------------
// Handling Link chemical cistron using "linkText" locator...
driver.findElement(By.linkText("Gmail")).click();

// Handling Link chemical cistron using "partialLinkText" locator...
driver.findElement(By.partialLinkText("Gma")).click();

// Handling Link chemical cistron using "Class Name" locator...
driver.findElement(By.className("gb_P")).click();

// Handling Link chemical cistron using "cssSelector" locator...
driver.findElement(By.cssSelector(".gb_P")).click();

// Handling Link chemical cistron using "xpath" locator...
driver.findElement(By.xpath(".//*[@id='gbw']/div/div/div[1]/div[1]/a")).click();
-------------------------------
6) Handling Radio Button

Operating Radio Button

> Check Displayed Status
> Check Enabled Status
> Check Selected Status

> Select / Click 
-------------------------------
Selenium WebDriver Test script:
WebDriver driver = novel FirefoxDriver();
driver.get("http://www.gcrit.com/build3/create_account.php?osCsid=7u1anl9ha5gejotirul66opl33");
boolean a = driver.findElement(By.xpath(".//*[@id='bodyContent']/form/div/div[2]/table/tbody/tr[1]/td[2]/input[1]")).isDisplayed();
System.out.println(a);//true

a = driver.findElement(By.xpath(".//*[@id='bodyContent']/form/div/div[2]/table/tbody/tr[1]/td[2]/input[1]")).isEnabled();
System.out.println(a);//true

a = driver.findElement(By.xpath(".//*[@id='bodyContent']/form/div/div[2]/table/tbody/tr[1]/td[2]/input[1]")).isSelected();
System.out.println(a);//false

driver.findElement(By.xpath(".//*[@id='bodyContent']/form/div/div[2]/table/tbody/tr[1]/td[2]/input[1]")).click();

a = driver.findElement(By.xpath(".//*[@id='bodyContent']/form/div/div[2]/table/tbody/tr[1]/td[2]/input[1]")).isSelected();
System.out.println(a);//true
-------------------------------
//Create Web Element too perform multiple operations on the Element

public static void main(String[] args) {
boolean status;
WebDriver driver = novel FirefoxDriver();
driver.get("http://www.gcrit.com/build3/create_account.php?osCsid=7u1anl9ha5gejotirul66opl33");
WebElement radioButton = driver.findElement(By.xpath(".//*[@id='bodyContent']/form/div/div[2]/table/tbody/tr[1]/td[2]/input[1]"));

status = radioButton.isDisplayed();
System.out.println(status);//true

status = radioButton.isEnabled();
System.out.println(status);//true

status = radioButton.isSelected();
System.out.println(status);//false

radioButton.click();

status = radioButton.isSelected();
System.out.println(status);//true

driver.close();
-------------------------------
7) Handling Drop Down Box

> Check Displayed Status
> Check Enabled Status

> Select an Item

> Return Items Count
-----------------------------------------------------------
Selenium WebDriver script

public static void main(String[] args) {
boolean status;
WebDriver driver = novel FirefoxDriver();
driver.get("http://www.gcrit.com/build3/create_account.php?osCsid=7u1anl9ha5gejotirul66opl33");
System.out.println(driver.findElement(By.name("country")).isDisplayed());//true
System.out.println(driver.findElement(By.name("country")).isEnabled());//true

Select dropdown = novel Select(driver.findElement(By.name("country")));

//dropdown.selectByIndex(1);
dropdown.selectByVisibleText("India");

List <WebElement> e = dropdown.getOptions();
System.out.println(e.size());

driver.close();
-------------------------------
8) Handling Check Box

> Check Displayed Status
> Check Enabled Status
> Check Selected Status

> Select
> Unselect
-------------------------------
Selenium WebDriver Script:

public static void main(String[] args) {
boolean status;
WebDriver driver = novel FirefoxDriver();
driver.get("file:///C:/Users/gcreddy/Desktop/HTMLExamples/MultipleCheckbox.html");
boolean displayedStatus = driver.findElement(By.xpath("html/body/input[3]")).isDisplayed();
boolean enabledStatus = driver.findElement(By.xpath("html/body/input[3]")).isEnabled();
boolean selectedStatus = driver.findElement(By.xpath("html/body/input[3]")).isSelected();
System.out.println(displayedStatus);//true
System.out.println(enabledStatus);//true
System.out.println(selectedStatus);//false

driver.findElement(By.xpath("html/body/input[3]")).click();

boolean selectedStatus2 = driver.findElement(By.xpath("html/body/input[3]")).isSelected();
System.out.println(selectedStatus2);//true

driver.findElement(By.xpath("html/body/input[3]")).click();

boolean selectedStatus3 = driver.findElement(By.xpath("html/body/input[3]")).isSelected();
System.out.println(selectedStatus3);//false
-------------------------------
// Create Web Element too perform operations ane past times one

public static void main(String[] args) {
boolean status;
WebDriver driver = novel FirefoxDriver();
driver.get("file:///C:/Users/gcreddy/Desktop/HTMLExamples/MultipleCheckbox.html");
WebElement checkBox = driver.findElement(By.xpath("html/body/input[3]"));

boolean displayedStatus= checkBox.isDisplayed();
boolean enabledStatus = checkBox.isEnabled();
boolean selectedStatus1= checkBox.isSelected();

System.out.println(displayedStatus);//true
System.out.println(enabledStatus);//true
System.out.println(selectedStatus1);//false

checkBox.click();

boolean selectedStatus2= checkBox.isSelected();
System.out.println(selectedStatus2);//true

checkBox.click();
boolean selectedStatus3= checkBox.isSelected();
System.out.println(selectedStatus3);//false
driver.close();
-------------------------------
8) Image, Image Button, Image Link

public static void main(String[] args) throws InterruptedException {
boolean status;
WebDriver driver = novel FirefoxDriver();
driver.get("https://www.google.co");
String imageTitle = driver.findElement(By.id("hplogo")).getAttribute("title");
System.out.println(imageTitle);

Thread.sleep(5000);

driver.navigate().to("http://newtours.demoaut.com/");
driver.findElement(By.name("login")).click();

Thread.sleep(5000);

driver.navigate().to("http://www.seleniumhq.org/");
driver.findElement(By.xpath(".//*[@id='choice']/tbody/tr/td[2]/center/a/img")).click();
-------------------------------
10) Handling Web Table/HTML Table

> Check Displayed Status

> Get/Return Cell Value
> Return Rows Count
> Return Cells Count

Selenium WebDriver Test Steps:
WebDriver driver = novel FirefoxDriver();
driver.manage().window().maximize();
driver.get("file:///C:/Users/GCREDDY/Desktop/HTMLExamples/htmlTable.html");
boolean displayStatus = driver.findElement(By.id("students")).isDisplayed();
System.out.println(displayStatus);//true

WebElement studentsTable = driver.findElement(By.id("students"));

List <WebElement> rows = studentsTable.findElements(By.tagName("tr"));
int rowcount = rows.size();
System.out.println("Rows Count is: " +rowcount);

List <WebElement> cells = studentsTable.findElements(By.tagName("td"));
int cellCount = cells.size();
System.out.println("Cells Count is: " + cellCount);

System.out.println("Colums Count is: "+ cells.size()/rows.size());

String cellValue = driver.findElement(By.xpath(".//*[@id='students']/tbody/tr[2]/td[2]")).getText();
System.out.println(cellValue);

driver.close();
}
}
-------------------------------
Using Chrome browser:

//Instantiate the Chrome Browser driver
System.setProperty("webdriver.chrome.driver", "E:/chromedriver.exe");
//Create Chrome Browser driver
WebDriver driver = novel ChromeDriver();
driver.manage().window().maximize();
driver.get("file:///C:/Users/GCREDDY/Desktop/HTMLExamples/htmlTable.html");
boolean displayStatus = driver.findElement(By.id("students")).isDisplayed();
System.out.println(displayStatus);//true

WebElement studentsTable = driver.findElement(By.id("students"));

List <WebElement> rows = studentsTable.findElements(By.tagName("tr"));
int rowcount = rows.size();
System.out.println("Rows Count is: " +rowcount);

List <WebElement> cells = studentsTable.findElements(By.tagName("td"));
int cellCount = cells.size();
System.out.println("Cells Count is: " + cellCount);

System.out.println("Colums Count is: "+ cells.size()/rows.size());

String cellValue = driver.findElement(By.xpath(".//*[@id='students']/tbody/tr[2]/td[2]")).getText();
System.out.println(cellValue);

driver.close();
}
}
-------------------------------
11) Handling Frames...

> HTML Frames are used to dissever the Browser window into multiple sections, where each section
can charge a separate HTML document

> Frames are Sections of Web page displed on Top window

> Whenever nosotros access the page thus focus on the transcend window.
-------------------------------
Note: If It is Manual Testing, nosotros no bespeak to focus on Frames, nosotros tin access Elements inward whatsoever frame directly.

In Test Automation using Selenium Webdriver, offset nosotros bespeak to switch to a frame thus nosotros tin access
elements inward that frame.
-------------------------------
Switch from Top window to a Frame is done inward 2 ways,

i) Using Frame Index
ii) Using Frame Name
-------------------------------
i) Using Frame Index

Syntax:
driver.switchTo().frame(int index);

ii) Using Frame Name
driver.switchTo().frame("String Frame Name");
-------------------------------
WebDriver driver = novel FirefoxDriver();
driver.get("http://seleniumhq.github.io/selenium/docs/api/java/index.html");
driver.manage().window().maximize();
//Switch from the Top window to third Frame using Frame Index
driver.switchTo().frame(2);
driver.findElement(By.linkText("org.openqa.selenium")).click();
-------------------------------
WebDriver driver = novel FirefoxDriver();
driver.get("http://seleniumhq.github.io/selenium/docs/api/java/index.html");
driver.manage().window().maximize();
//Switch from the Top window to third Frame using Frame Name
driver.switchTo().frame("classFrame");
driver.findElement(By.linkText("org.openqa.selenium")).click();
-------------------------------
Test Requirement:

> Launch the Web Page that has multiple Frames,
> Operate an Element inward the third Frame,
> Operate an Element inward the 1st Frame
-------------------------------
Steps for selenium WebDriver exam Script:

> Launch the Web Page that has multiple Frames,
> Switch from transcend window to third Frame
> Access an Element
> Back to Top window (default)
> Switch from Top window to 1st Frame
> Access an Element
-------------------------------
WebDriver driver = novel FirefoxDriver();
driver.get("http://seleniumhq.github.io/selenium/docs/api/java/index.html");
driver.manage().window().maximize();
//Switch from the Top window to third Frame using Frame Name
driver.switchTo().frame("classFrame");
driver.findElement(By.linkText("org.openqa.selenium")).click();

driver.switchTo().defaultContent();

driver.switchTo().frame("packageListFrame");
driver.findElement(By.linkText("com.thoughtworks.selenium")).click();
-------------------------------
WebDriver driver = novel FirefoxDriver();
driver.get("http://seleniumhq.github.io/selenium/docs/api/java/index.html");
driver.manage().window().maximize();
//Switch from the Top window to third Frame using Frame Index
driver.switchTo().frame(2);
driver.findElement(By.linkText("org.openqa.selenium")).click();

driver.switchTo().defaultContent();

driver.switchTo().frame(0);
driver.findElement(By.linkText("com.thoughtworks.selenium")).click();
driver.close();
-------------------------------

Sumber http://www.gcreddy.com/

No comments:

Post a Comment