anu17's Profile
Doctor
209
Points

Questions
10

Answers
33

  • Doctor Asked on October 10, 2014 in Selenium WebDriver.

     

    package mypackage;
    import java.util.concurrent.TimeUnit;
    import org.openqa.selenium.*;
     import org.openqa.selenium.firefox.FirefoxDriver;
    public class firsttestCase {
    private static WebDriver driver = null;
    public static void main(String[] args) throws InterruptedException {
    // Create a new instance of the Firefox driver
    driver = new FirefoxDriver();
    //Put a Implicit wait, this means that any search for elements on the page could take the time the implicit wait is set for before throwing exception
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    //Launch the Online Store Website
    driver.get("http://www.store.demoqa.com");
    // Find the element that's ID attribute is 'account'(My Account)
     String sTitle = driver.getTitle();
    // Storing Title length in Int variable
    int iTitleLength = driver.getTitle().length();
    // Printing Title name on Console
    System.out.println(sTitle);
    // Printing Title length on console
    System.out.println(iTitleLength);
    // Storing URL in String variable
    sTitle = driver.getCurrentUrl();
    // Storing URL length in Int variable
    iTitleLength = driver.getCurrentUrl().length();
    // Printing URL on Console
    System.out.println(sTitle);
    // Printing URL length on console
    System.out.println(iTitleLength);
    // Refreshing current page
    driver.get(driver.getCurrentUrl());
    // Storing Page Source in String variable
    String sPageSource = driver.getPageSource();
    // Storing Page Source length in Int variable
    int iPageSourceLength = driver.getPageSource().length();
    // Printing Page Source on console
    System.out.println(sPageSource);
    // Printing Page SOurce length on console
    System.out.println(iPageSourceLength);
    driver.findElement(By.xpath(".//*[@id='account']/a")).click();
    // Find the element that's ID attribute is 'log' (Username)
    // Enter Username on the element found by above desc.
    driver.findElement(By.id("log")).sendKeys("testuser_1");
    // Find the element that's ID attribute is 'pwd' (Password)
    // Enter Password on the element found by the above desc.
    driver.findElement(By.id("pwd")).sendKeys("Test@123");
    // Now submit the form. WebDriver will find the form for us from the element
    driver.findElement(By.id("login")).click();
    // Print a Log In message to the screen
    System.out.println(" Login Successfully, now it is the time to Log Off buddy.");
    // Find the element that's ID attribute is 'account_logout' (Log Out)
     Thread.sleep(1000);
    driver.findElement (By.xpath("/html/body/div[2]/div/div/header/div[1]/a")).click();
    // Close the driver
    driver.quit();
    }
    }
    

    This will give all browser commands practice

    • 1167 views
    • 1 answers
    • 0 votes
  • Doctor Asked on October 10, 2014 in Selenium WebDriver.

    http://www.toolsqa.com/selenium-webdriver/testng-data-provider-excel/
    This will help you

    • 1476 views
    • 1 answers
    • 0 votes
  • Doctor Asked on September 26, 2014 in Selenium WebDriver.

    You can you the absolute  xpath of web element to locate the image.

    • 14387 views
    • 8 answers
    • 1 votes
  • Doctor Asked on September 26, 2014 in Selenium WebDriver.

    This  way you can read the rows and clms from excel file

    package utility;

    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;

    import org.apache.poi.xssf.usermodel.XSSFCell;
    import org.apache.poi.xssf.usermodel.XSSFRow;
    import org.apache.poi.xssf.usermodel.XSSFSheet;
    import org.apache.poi.xssf.usermodel.XSSFWorkbook;
    import org.apache.poi.ss.usermodel.*;

    public class Read_exl {
    public  String filelocation;
    public  FileInputStream ipstr = null;
    public  FileOutputStream opstr =null;
    private XSSFWorkbook wb = null;
    private XSSFSheet ws = null;

    public Read_exl(String filelocation) {
    this.filelocation=filelocation;
    try {
    ipstr = new FileInputStream(filelocation);
    wb = new XSSFWorkbook(ipstr);
    ws = wb.getSheetAt(0);
    ipstr.close();
    } catch (Exception e) {
    e.printStackTrace();
    }

    }

    //To retrieve No Of Rows from .xls file’s sheets.
    public int retrieveNoOfRows(String wsName){
    int sheetIndex=wb.getSheetIndex(wsName);
    if(sheetIndex==-1)
    return 0;
    else{
    ws = wb.getSheetAt(sheetIndex);
    int rowCount=ws.getLastRowNum()+1;
    return rowCount;
    }
    }

    //To retrieve No Of Columns from .cls file’s sheets.
    public int retrieveNoOfCols(String wsName){
    int sheetIndex=wb.getSheetIndex(wsName);
    if(sheetIndex==-1)
    return 0;
    else{
    ws = wb.getSheetAt(sheetIndex);
    int colCount=ws.getRow(0).getLastCellNum();
    return colCount;
    }
    }

    This answer accepted by surekha. on October 27, 2014 Earned 15 points.

    • 1679 views
    • 1 answers
    • 0 votes
  • Doctor Asked on September 24, 2014 in Selenium WebDriver.

    https://www.udemy.com/automation-testing-using-junit/

    This also helps

    • 616 views
    • 2 answers
    • 0 votes
  • Doctor Asked on September 24, 2014 in Selenium WebDriver.

    Can you Provide the URL?
    Can you provide the complete div tag

    • 1132 views
    • 3 answers
    • 0 votes
  • Doctor Asked on September 23, 2014 in Selenium WebDriver.

    You can Actions class for this.  When you move your mouse on a particular item the it displays all the dropdowns under the item .  To handle such situations you  can locate the element  and perfom().

    Actions act = new Actions(driver);
    act.moveToElement(locate elemente ).build(). PErform();
    //here the mouse will move to the element and you san see the dropdown
    Thread.sleep(1000);
    //if you wnat click the dropdown item then locate it and click it
    act.moveToElement(element location).click().perform();

    try this ..

    • 4638 views
    • 2 answers
    • 0 votes
  • Doctor Asked on September 23, 2014 in Selenium WebDriver.

    To handle multiple windows getWindowHandles() isused with this selenium will generates a alphanumeric id to each window. Using this id we can get control among several windows.

    Set<String> allwin = driver.getWindowHandles();
    String win1 = allwin .toArray[][0];
    String win2= allwin.toArray[][1];
    driver.switchTo().window(win1);
    driver.switchTo().window(win2);

    so on

    • 948 views
    • 2 answers
    • 0 votes
  • Doctor Asked on September 21, 2014 in Selenium WebDriver.

    you can visit this site

    http://www.toolsqa.com/selenium-webdriver/testng-testsuite/
    this will help you

    This answer accepted by kishore. on December 12, 2014 Earned 15 points.

    • 834 views
    • 3 answers
    • 0 votes
  • Doctor Asked on September 21, 2014 in Selenium WebDriver.

    http://www.toolsqa.com/selenium-webdriver/testng-testsuite/

    • 834 views
    • 3 answers
    • 0 votes
  • Doctor Asked on September 16, 2014 in Selenium WebDriver.

    Please check your firefox and webdriver versions.  Firefox version 32 will not work with selenium 2.41.

    • 1368 views
    • 4 answers
    • 0 votes
  • Doctor Asked on September 16, 2014 in Selenium WebDriver.

    You can try this

    Thread.sleep(1000);
    drive.findElement(By.xpath(“/html/body/div[2]/div/div/header/div[1]/a”)).click()

    May be this may work

    • 6321 views
    • 7 answers
    • 0 votes
  • Doctor Asked on September 16, 2014 in Selenium WebDriver.

    I solved the problem by updating the Firefox to  lower versions.  All my scripts are working now.

    thanks
    Anu

    • 625 views
    • 1 answers
    • 0 votes
  • Doctor Asked on September 9, 2014 in Selenium WebDriver.

    Can you give the code for the above errot

    • 5585 views
    • 3 answers
    • 0 votes
  • Doctor Asked on September 9, 2014 in Selenium WebDriver.

    When you give the xpath  and two buttons have same id , by default selenium takes the first button.  you can give starts with or contains or index number

    • 1338 views
    • 6 answers
    • 2 votes
  • Doctor Asked on September 8, 2014 in Selenium WebDriver.

    Can you give the overview of those frameworks

    • 964 views
    • 5 answers
    • 0 votes
  • Doctor Asked on September 8, 2014 in Selenium WebDriver.

    What kind of frameworks you are using in your projects apart from DDF and MDF

    • 964 views
    • 5 answers
    • 0 votes
  • Doctor Asked on September 8, 2014 in Selenium WebDriver.

    • 961 views
    • 2 answers
    • 0 votes
  • Doctor Asked on September 4, 2014 in Selenium WebDriver.

    Hi sivaprasad

    Driver.get(baseurl)  navigates to the given url t could be baseurl any other url you give
    navigate() will be used  for browser navigation in following ways
    driver.navitage().to(url);
    driver.navigate().backward()
    driver.navigate().forward();
    driver.navigate().refresh()
    etc

    • 4882 views
    • 3 answers
    • 1 votes
  • Doctor Asked on September 4, 2014 in Selenium WebDriver.

    Hi kishore,

    you can you firebug addon to firfox to locate the element or you can use contains, startswith, text in xpath of element

    • 720 views
    • 3 answers
    • 0 votes
  • Doctor Asked on September 3, 2014 in Selenium WebDriver.

    What is OLE container?

    • 1053 views
    • 3 answers
    • 0 votes
    • 851 views
    • 2 answers
    • 0 votes
  • Doctor Asked on September 3, 2014 in Selenium WebDriver.

    Hi Paso,

    Can you share the solution?

    • 3857 views
    • 7 answers
    • 0 votes
  • Doctor Asked on September 2, 2014 in Selenium WebDriver.

    Hi Yogesh,
    You can do like this

     
    package mypackage;
    import org.openqa.selenium.By;
     import org.openqa.selenium.WebDriver;
     import org.openqa.selenium.WebElement;
     import org.openqa.selenium.firefox.FirefoxDriver;
    public class popuphandling {
    public static void main(String[] args ) throws InterruptedException
     {
     WebDriver driver= new FirefoxDriver();
     driver.get("http://www.facebook.com");
     WebElement sign = driver.findElement(By.xpath("/html/body/div/div[2]/div[1]/div/div[1]/div/div/div[2]/div/div/div/div/form/div[1]/div[5]/div[2]/a"));
     sign.click();
     Thread.sleep(2000);
    driver.findElement(By.xpath("/html/body/div/div[2]/div[3]/div/div/div/div[2]/a")).click();
    Thread.sleep(2000);
    }
     }
    

     

    • 1361 views
    • 3 answers
    • 0 votes
  • Doctor Asked on September 2, 2014 in Selenium WebDriver.

    Hi balajinatarajan,

    I will give a small example.  Lets get all the links for craigslist.org site.  May be this may help you

     

    import package name;
     import org.openqa.selenium.*;
     import org.openqa.selenium.firefox.FirefoxDriver;
     import java.util.List;
     import java.util.concurrent.TimeUnit;
     import org.openqa.selenium.By;
    public void class allLinksOfthe Page
     {
     WebDriver driver= new FirefoxDriver();
     driver.manage().windows().maxmize()'
     driver.get("http://www.craigslist.org/about/sites");
     driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
     driver.findElement(By.xpath(/html/body/article/section/div[3]/div[2]/ul[9]/li[1]/a)).click();
     try{
    List<WebElement> no= driver.findElements(By.tagName("a"));
     int noflinks = no.size();
     System.out.println("no of links available in current page is" + noflinks);
     for( WebElement pagelink : no)
     {
     String pagelinktext = pagelink.getText();
     String linkname     = pagelink.getAttribute("href");
     System.out.println("text of the link is    "+   pagelinktext);
     System.out.println("name of the link is    "+    linkname);
    }
    } catch(Exception e)
     {
     System.out.println("error"+e);
     }
     }
    

     

    This answer accepted by balajinatarajan. on September 3, 2014 Earned 15 points.

    • 1974 views
    • 2 answers
    • 0 votes