Pages

Sunday, March 27, 2016

Sibling concepts(X path Axis)

                                     Sibling concepts

1) following
2) following-sibling
3) preceding-sibling
4) parent
5) preceding
6) /..
7) ancestor
8) descendant
9) child

user url

http://www.w3schools.org/1999/xhtml


$x("//div[@id='header']/child::div")
$x("//div[@id='header']/child::div/child::h1")
$x("//div[@id='header']/child::div/ancestor::*")
$x("//div[@class='domain ']/ancestor::body")
$x("//div[@class='domain ']/ancestor::div")
$x("//div[@id='header']/child::div/ancestor::div")


$x("//body[@class='twoclick content']/child::div")
$x("//body[@class='twoclick content']/child::div[2]")

$x("//div[@id='header']/following-sibling::*")
$x("//div[@id='header']/following-sibling::div[2]")

$x("//div[@id='header']/following-sibling::div[2]/descendant::*")
$x("//div[@id='header']/following-sibling::div[2]/descendant::img")
$x("//div[@id='header']/following-sibling::div[2]/descendant::div[2]")
$x("//*[@id='footer']/descendant::div[position()=2]")

$x("//div[@id='disclaimer']/ancestor::div")
$x("//div[@id='disclaimer']/ancestor::div/ancestor::*")
$x("//span[@class='sedologo']/ancestor::div[position()=2]")
$x("//span[@class='sedologo']/ancestor::div[2]")

$x("//div[@id='footer']/preceding-sibling::div[2]")
$x("//div[@id='content']/following-sibling::div/child::div[2]/span[@class='sedologo']/following-sibling::*")

$x("//div[@id='footer']/parent::*")
$x("//*[@id='footer']/parent::node()")
$x("//div[@id='footer']/parent::div[1]")

$x("//div[@id='footer']/self::*")
$x("//div[@id='footer']/self::div")


http://bhanupratapdatastructurealgo.blogspot.in/
http://bhanupratapcorejavaprogramming.blogspot.in/
http://bhanupratapseleniumhybridframework.blogspot.in/











Sunday, January 24, 2016

Test Automation interview questions ~ Software Testing

Test Automation interview questions ~ Software Testing



http://bhanupratapcorejavaprogramming.blogspot.in/

All Kind Of locators in selenium

driver.findElement(By.xpath("(//input[@type='checkbox'])[position()=3]")).click();
driver.findElement(By.xpath("(//input[@type='checkbox'])[last()-1]")).click();
driver.findElement(By.xpath("(//span[@class='hit'])[last()]")).getText();
/**
* To locate last checkbox, You can use It as bellow.
*/

driver.findElement(By.xpath("//input[@type='checkbox'])[last()]"));
driver.findElement(By.xpath("td[contains(text(),'Dog')]/following-sibling::td/input[@type='checkbox']"));

/**
* preceding-sibling Here Is reverse condition. Checkbox comes first and
* value text comes last so concept Is same but we have to use word
* preceding-sibling In XPath as bellow.
*/
driver.findElement(By.xpath("//td[contains(text(),'Cow')]/preceding-sibling::td/input[@type='checkbox']"));

/**
* We can use window().getSize() method to get size of window.
*/

driver.manage().window().getSize().getHeight();
/**
* WebDriver getPosition method used to get window position x,y
* coordinates.
*/

System.out.println("Window position X coordinates Is -> " + driver.manage().window().getPosition().getX());
System.out.println("Window position Y coordinates Is -> " + driver.manage().window().getPosition().getY());
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.switchTo().window("windowName");
Alert alert = driver.switchTo().alert();
driver.navigate().forward();
driver.navigate().back();

/**
* Drag Drop of element
*/
WebElement element = driver.findElement(By.name("source"));
WebElement target = driver.findElement(By.name("target"));
Actions action = new Actions(driver);
action.dragAndDrop(element, target).build().perform();
(new Actions(driver)).dragAndDrop(element, target).perform();

driver.findElement(By.xpath("//a[starts-with(@href, 'mylink')]"));
driver.findElement(By.xpath("//a[contains(@href, 'key_word')]"));
driver.findElement(By.xpath("//input[starts-with(@id, 'text-')]"));
driver.findElement(By.xpath("//span[starts-with(@id, 'revit_form_Button_') and ends-with(@id, '_label']"));
driver.findElement(By.xpath("//span[starts-with(@id, 'revit_')][@class='dijitButtonText']"));
driver.findElement(By.xpath("//span[starts-with(@id, 'revit_')]"));

Set<String> windows = driver.getWindowHandles();
Iterator<String> itr = windows.iterator();

/**
* patName will provide you parent window
*/
String patName = itr.next();

/**
* chldName will provide you child window
*/
String chldName = itr.next();

/**
* Switch to child window
*/
driver.switchTo().window(chldName);

/**
* Do normal selenium code for performing action in child window
*/

/**
* To come back to parent window
*/
driver.switchTo().window(patName);

driver.findElement(By.xpath("")).getAttribute("name");
driver.findElements(By.xpath("")).get(8);

driver.findElement(By.id("")).getText();
driver.manage().getCookies();

driver.findElement(By.xpath("//*[@id='c_pass']")).sendKeys(Keys.ENTER);

Select select = new Select(driver.findElement(By.xpath("")));
List<WebElement> opt = select.getOptions();
System.out.println(opt.get(3));
select.selectByIndex(0);
select.selectByValue("test");
select.selectByVisibleText("test");

String CurrentUrl = driver.getCurrentUrl();
System.out.println(CurrentUrl);
String PageSource = driver.getPageSource();
System.out.println(PageSource);

int rowCount=driver.findElements(By.xpath("//table[@id='DataTable']/tbody/tr")).size();
        System.out.println(rowCount);
int columnCount=driver.findElements(By.xpath("//table[@id='DataTable']/tbody/tr/td")).size();
System.out.println(columnCount);

List<WebElement> oRadioButton = driver.findElements(By.name("toolsqa"));

// Create a boolean variable which will hold the value (True/False)

boolean bValue = false;

// This statement will return True, in case of first Radio button is
// selected

bValue = ((WebElement) oRadioButton.get(0)).isSelected();

// This will check that if the bValue is True means if the first radio
// button is selected

if (bValue = true) {

// This will select Second radio button, if the first radio button
// is selected by default

((WebElement) oRadioButton.get(1)).click();

} else {

// If the first radio button is not selected by default, the first
// will be selected

((WebElement) oRadioButton.get(0)).click();

}


 String sValue = "Lakshay Sharma";

 System.out.println(" What is your full name");

 Assert.assertEquals("Lakshay Sharma", sValue);
 Assert.assertTrue(true);
 Assert.assertTrue(true, "login is done");
}

Sunday, July 5, 2015

Selenium Project Structure









How to get all options in a drop-down list by Selenium webdriver




<TD>
  <select name = "time_zone">
    <option value "-09:00"><script>timezone.Alaska</script></option>
    <option value "+00:00"><script>timezone.England</script></option>
    <option value "+02:00"><script>timezone.Greece</script></option>
    <option value "+05:30"><script>timezone.India</script></option>
  </select>
<TD>


IWebElement elem = driver.FindElement(By.XPath("//select[@name='time_zone']"));
List<IWebElement> options = elem.FindElements(By.TagName("option"));

How to interact with Drop down Boxes in Selenium

How to interact with Drop down Boxes. We can select an option using
selectByVisibleText
selectByIndex
selectByValue' methods.


import java.util.concurrent.TimeUnit;

import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

public class webdriverdemo {
   public static void main(String[] args) throws InterruptedException {
 
      WebDriver driver = new FirefoxDriver();
     
      //Puts a Implicit wait, Will wait for 10 seconds before throwing exception
      driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
     
      //Launch website
      driver.navigate().to("http://www.calculator.net/interest-calculator.html");
      driver.manage().window().maximize();
     
      //Selecting an item from Drop Down list Box
      Select dropdown = new Select(driver.findElement(By.id("ccompound")));
      dropdown.selectByVisibleText("continuously");
     
      //you can also use dropdown.selectByIndex(1) to select second element as index starts with 0.
      //You can also use dropdown.selectByValue("annually");
     
      System.out.println("The Output of the IsSelected " + driver.findElement(By.id("ccompound")).isSelected());
      System.out.println("The Output of the IsEnabled " + driver.findElement(By.id("ccompound")).isEnabled());
      System.out.println("The Output of the IsDisplayed " + driver.findElement(By.id("ccompound")).isDisplayed());
     
      driver.close();
   }
}

Friday, July 3, 2015

How To scroll the page

Make sure to import org.openqa.selenium.JavascriptExecutor;


\JavascriptExecutor js = (JavascriptExecutor)driver;
// if the element is on top. js.executeScript("scroll(250, 0)"); // if the element is on bottom. js.executeScript("scroll(0, 250)");


WebElement element = driver.findElement(By.id(""));         JavascriptExecutor js =(JavascriptExecutor)driver;         js.executeScript("window.scrollTo(0,"element.getLocation().y+")");         element.click();


 You can also try the below using X or Y position
        WebElement element = driver.findElement(By.id(""));
        JavascriptExecutor js =(JavascriptExecutor)driver;
        js.executeScript("window.scrollTo(0,"element.getLocation().y+")");
        element.click();