Re: Add location Program getting an exception as java.lang.IndexOutOfBoundsException: Index: 4, Size: 4(Req cod

17 views
Skip to first unread message

Ratna Kumar

unread,
May 26, 2017, 9:49:27 AM5/26/17
to qapl...@googlegroups.com

If button is enabled then click on next and verify the table. If next button is disabled then dont click on next. nd the loop.

Thts how u need to handle the pagination.


On 26-May-2017 5:35 PM, "Nataraj M" <mnata...@gmail.com> wrote:
hai,
i dont see pagination. please make it

On 15 May 2017 at 19:05, Buddi Chaitanya <chaitu...@gmail.com> wrote:
I verified the the added location with search it's worked fine , but please give me solution for below issue

More Info on issue:While handling pagination, in the anchor tag, pages, next and last links are there. Suppose if 2 pages are there, then anchor tag is displayed as <a>2</a>,
<a>Next</a> and <a>Last</a>, so for loop trying to click on next link , but it's not highlighted, since 2nd page is the last page, so getting an error



On Monday, May 15, 2017 at 6:21:46 PM UTC+5:30, Buddi Chaitanya wrote:
Program:

package addLocation;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;

import java.awt.AWTException;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;

import com.gargoylesoftware.htmlunit.javascript.host.media.webkitMediaStream;
//import com.sun.jna.Structure.FFIType.size_t;

public class AddLocation {
    public static void main(String[] args)throws Exception {
        //System.setProperty("webdriver.gecko.driver", "D:\\Selenium QAPlanet\\Drivers\\geckodriver-v0.15.0-win64\\geckodriver.exe");
        System.setProperty("webdriver.chrome.driver", "D:\\Selenium QAPlanet\\Drivers\\chromedriver_win32\\chromedriver.exe");
        //FirefoxDriver driver=new FirefoxDriver();
        ChromeDriver driver=new ChromeDriver();
        driver.manage().window().maximize();
        WebDriverWait wait=new WebDriverWait(driver, 60);
        Actions Act=new Actions(driver);
        driver.get("http://apps.qaplanet.in/qahrm/login.php");
        //vrifying the home page title
        wait.until(ExpectedConditions.titleIs("OrangeHRM - New Level of HR Management"));
        if(driver.getTitle().equals("OrangeHRM - New Level of HR Management"))
        {
            System.out.println("Home Page is displayed");
        }
        //creating webelements for username,password,login and clear
        WebElement ObjUn=wait.until(ExpectedConditions.presenceOfElementLocated(By.name("txtUserName")));
        WebElement ObjPwd=wait.until(ExpectedConditions.presenceOfElementLocated(By.name("txtPassword")));
        WebElement ObjLogin=wait.until(ExpectedConditions.presenceOfElementLocated(By.name("Submit")));
        WebElement ObjClear=wait.until(ExpectedConditions.presenceOfElementLocated(By.name("clear")));
    //verifying the username
        if(ObjUn.isDisplayed())
    {
        System.out.println("username field is displayed");
    }
    else
    {
        System.out.println("username field is not displayed");
    }
        //verifying the password field
    if(ObjPwd.isDisplayed())
    {
        System.out.println("Password field is displayed");
    }
    else
    {
        System.out.println("Password field is not displayed");
    }
    //verifying the both login and clear fields
    if(ObjLogin.isDisplayed() && ObjClear.isDisplayed())
    {
        System.out.println("Login button and clear buttons are displayed properly");
    }
    else
    {
        System.out.println("Login button and clear buttons are not displayed properly");
    }

    //storing the username and password in objects
    String StrUname="qaplanet1";
    String StrPwd="user1";
    //entering username
    ObjUn.sendKeys(StrUname);
    //entering password
    ObjPwd.sendKeys(StrPwd);
    //click on login
    ObjLogin.click();
    //After logged into HRM, verifying the Home page
    Boolean res=wait.until(ExpectedConditions.titleIs("OrangeHRM"));
    //verifying home page
    if(res)
    {
        System.out.println("home page is displayed properly");
    }
    else
    {
        System.out.println("home page is not displayed");
    }
    //verifying welcome message
    String welcometext=driver.findElement(By.xpath("//ul[@id='option-menu']/li[1]")).getText();
    if(welcometext.equals("Welcome "+StrUname))
    {
        System.out.println("welcome "+StrUname+" is displayed and verified");
    }
    else
    {
        System.out.println("welcome text is not displayed and verified");
    }
    //verifying the change password link and Logout link
    WebElement ObjChangePwd=driver.findElement(By.xpath("//ul[@id='option-menu']/li[2]"));
    WebElement ObjLogout=driver.findElement(By.xpath("//ul[@id='option-menu']/li[3]"));
    if(ObjChangePwd.isDisplayed() && ObjLogout.isDisplayed())
    {
        System.out.println("change password and logout is displayed");
    }
    else
    {
        System.out.println("change password and logout is not displayed");
    }
//focus on Admin
    WebElement objAdmin=driver.findElement(By.linkText("Admin"));
Act.moveToElement(objAdmin).pause(6000).perform();
//webelements for company.job, etc..
WebElement objCompany=driver.findElement(By.xpath("//li[@id='admin']/ul/li/a/span"));
WebElement objJob=driver.findElement(By.xpath("//li[@id='admin']/ul/li[2]/a/span"));
WebElement objQualification=driver.findElement(By.xpath("//li[@id='admin']/ul/li[3]/a/span"));
WebElement objSkills=driver.findElement(By.xpath("//li[@id='admin']/ul/li[4]/a/span"));
    if(objCompany.isDisplayed())
    {
        System.out.println("company link is displayed properly");
    }
    else
    {
        System.out.println("company link is not displayed");
    }
    if(objJob.isDisplayed())
    {
        System.out.println("Job link is displayed properly");
    }
    else
    {
        System.out.println("Job link is not displayed");
    }
    if(objQualification.isDisplayed())
    {
        System.out.println("qualification link is displayed properly");
    }
    else
    {
        System.out.println("qualification link is not displayed");
    }
    if(objSkills.isDisplayed())
    {
        System.out.println("skills link is displayed properly");
    }
    else
    {
        System.out.println("skills link is not displayed");
    }
    //focusing on company info
   
    WebElement ObjCompanyInfo=wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//li[@id='admin']/ul/li/a/span")));
    Act.moveToElement(ObjCompanyInfo).build().perform();
    //ObjCompanyInfo.click();
    Thread.sleep(3000);
    //Verifying General,Locations, Structure, Properties
    WebElement objCompanyInfo_General=driver.findElement(By.xpath("//li[@id='admin']/ul/li/ul/li/a/span"));
    WebElement objCompanyInfo_Locations=driver.findElement(By.xpath("//li[@id='admin']/ul/li/ul/li[2]/a/span"));
    WebElement objCompanyInfo_CompanyStructure=driver.findElement(By.xpath("//li[@id='admin']/ul/li/ul/li[3]/a/span"));
    WebElement objCompanyInfo_CompanyProperty=driver.findElement(By.xpath("//li[@id='admin']/ul/li/ul/li[4]/a/span"));
    if(objCompanyInfo_General.isDisplayed())
    {
        System.out.println("CompanyInfo_General link is displayed");
    }
    else
    {
        System.out.println("CompanyInfo_General link is not displayed");
    }
    if(objCompanyInfo_Locations.isDisplayed())
    {
        System.out.println("CompanyInfo_Locations link is displayed");
    }
    else
    {
        System.out.println("CompanyInfo_Locations link is not displayed");
    }
    if(objCompanyInfo_CompanyStructure.isDisplayed())
    {
        System.out.println("CompanyInfo_CompanyStructure link is displayed");
    }
    else
    {
        System.out.println("CompanyInfo_CompanyStructure link is not displayed");
    }
    if(objCompanyInfo_CompanyProperty.isDisplayed())
    {
        System.out.println("CompanyInfo_CompanyProperty link is displayed");
    }
    else
    {
        System.out.println("CompanyInfo_CompanyProperty link is not displayed");
    }
   
    //clicking on locations
    objCompanyInfo_Locations.click();
    //wait for frame to be loaded
    wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.id("rightMenu")));
    //verifying the Companyinfo_locations text
    WebElement objLocations_info=driver.findElement(By.xpath("//div[@class='maincontent']/form/div/h2"));
    assertEquals(objLocations_info.getText(),"Company Info : Locations");
    System.out.println("Company Info : Locations  text is displayed");

    //verifying location page with serach by
    WebElement objSearchBy=driver.findElement(By.xpath("//div[@class='maincontent']/form/div[2]/label[1]"));
    assertTrue(objSearchBy.isDisplayed());
    System.out.println("Search By is displayed");
WebElement objSearchEditBox=driver.findElement(By.xpath("//div[@class='maincontent']/form/div[2]/input[1]"));
assertTrue(objSearchEditBox.isDisplayed());
System.out.println("Search Edit box is displayed");
WebElement objSearchButton=driver.findElement(By.xpath("//div[@class='maincontent']/form/div[2]/input[2]"));   
assertTrue(objSearchButton.isDisplayed());
System.out.println("Search Button is displayed");
WebElement objResetButton=driver.findElement(By.xpath("//div[@class='maincontent']/form/div[2]/input[3]"));   
assertTrue(objResetButton.isDisplayed());
System.out.println("Reset Button is displayed");
WebElement objAddButton=driver.findElement(By.xpath("//div[@class='actionbuttons']/input[1]"));   
assertTrue(objAddButton.isDisplayed());
System.out.println("Add Button is displayed");
WebElement objDeleteButton=driver.findElement(By.xpath("//div[@class='actionbuttons']/input[2]"));   
assertTrue(objDeleteButton.isDisplayed());
System.out.println("Add Button is displayed");
    //clicking on Add button
objAddButton.click();
System.out.println("Add button is cliked");
    wait.until(ExpectedConditions.textToBePresentInElementLocated(By.xpath("//div[@class='maincontent']/div/h2"),"Company Info : Locations"));
    System.out.println("Company Info : Locations text is displayed properly");
    //verifying name field
    WebElement objNamField=driver.findElement(By.id("txtLocDescription"));
    assertTrue(objNamField.isDisplayed());
    System.out.println("Name text field is displayed");
    //verifying country dropdown
    WebElement objCountryDropdpwn=driver.findElement(By.id("cmbCountry"));
    assertTrue(objCountryDropdpwn.isDisplayed());
    System.out.println("CountryDropdpwn is displayed");
    //verifying state
    WebElement objState=driver.findElement(By.id("txtState"));
    assertTrue(objState.isDisplayed());
    System.out.println("State field is displayed");
    //verifying city
    WebElement objCity=driver.findElement(By.id("cmbDistrict"));
    assertTrue(objCity.isDisplayed());
    System.out.println("City field is displayed");
    WebElement objAddress=driver.findElement(By.id("txtAddress"));
    assertTrue(objAddress.isDisplayed());
    System.out.println("Address field is displayed");
    //by keeping all fields blank , clicking on save and handling alerts
    WebElement objZipcode=driver.findElement(By.id("txtZIP"));
    WebElement objSaveloc=driver.findElement(By.id("editBtn"));
    objSaveloc.click();
    //wait for alert page
    Alert a=wait.until(ExpectedConditions.alertIsPresent());
    //if(a.getText().equalsIgnoreCase("Please correct the following     %n     - Location Name has to be specified  %n    - Country should be selected! %n   - Address should be specified  %n    - Zip Code should be specified"))
    //{
     System.out.println(a.getText());
    a.accept();
    //}
   
    //enter name field
    String StrLocName="hyderabadmindspace";
    objNamField.clear();
    objNamField.sendKeys(StrLocName);
objSaveloc.click();
    Alert al=wait.until(ExpectedConditions.alertIsPresent());
    System.out.println(al.getText());
    al.accept();
    //selecting country dropdwon
   
    Select s=new Select(objCountryDropdpwn);
    /*List <WebElement> objdropdowncount=s.getOptions();
    //System.out.println(objdropdowncount.size());
    int isize=objdropdowncount.size();
    for(int i=1;i<isize;i++)
    {
        String sValue=objdropdowncount.get(i).getText();
    //System.out.println(sValue);
    }*/
    s.selectByValue("IN");
    if(s.getFirstSelectedOption().getText().equals("India"))
    {
        System.out.println("selected option in drop down is India");
    }
    else
    {
        System.out.println("India is not selected");
    }
    //System.out.println(s.getFirstSelectedOption().getText());
    //System.out.println(s.getAllSelectedOptions());
    objSaveloc.click();
    Alert a2=wait.until(ExpectedConditions.alertIsPresent());
    System.out.println(a2.getText());
    a2.accept();
    //enter the address
    objAddress.clear();
    objAddress.sendKeys("Yellareddy guda, Ameerpet");;
    objSaveloc.click();
    Alert a3=wait.until(ExpectedConditions.alertIsPresent());
    System.out.println(a3.getText());
    a3.accept();
objZipcode.clear();
objZipcode.sendKeys("12345");
    objSaveloc.click();
    driver.switchTo().defaultContent();
    System.out.println("switches to default frame");
    wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("//iframe[@id='rightMenu']")));
    //wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.id("rightMenu")));
    //verifying the locations page is displayed or not
    System.out.println("switches to inline frame");
    if(driver.findElement(By.xpath("//div[@class='maincontent']/form/div/h2")).getText().equals("Company Info : Locations"))
    {
    //WebElement objLocationss_info=driver.findElement(By.xpath("//div[@class='maincontent']/form/div/h2"));
    //assertEquals(objLocationss_info.getText(),"Company Info : Locations");
    System.out.println("Company Info : Locations  text is displayed");
    }
    else
    {
        System.out.println("Company Info : Locations  text is not displayed");
    }
    //wait.until(ExpectedConditions.textToBePresentInElementLocated(By.xpath("//div[@class='maincontent']/div/h2"),"Company Info : Locations"));
    //System.out.println("Company Info : Locations text is displayed properly");
    //by for loop verifying the loc info
    //Thread.sleep(3000);
   
    /*int rowcount=driver.findElements(By.xpath("//table[@class='data-table']/tbody/tr")).size();
    System.out.println(rowcount);
    int i;
    for(i=1;i<=rowcount;i++)
    {
        //String StrEmpName=driver.findElement(By.xpath("//table[@class='data-table']/tbody/tr["+i+"]/td[3]/a")).getText();
        String LocNamee=driver.findElement(By.xpath("//table[@class='data-table']/tbody/tr["+i+"]/td[3]/a")).getText();
    System.out.println(LocNamee);
        if(LocNamee.equals(StrLocName))
    {
        System.out.println("Locname is "+StrLocName+" and is displayed at: "+i);
    break;
    }*/
    /*else
    {
        System.out.println("Locname is not there");
    }*/
   
    List<WebElement> allrows = driver.findElements(By.xpath("//table[@class='data-table']/tbody/tr"));
    List<WebElement> allpages = driver.findElements(By.xpath("//div[@class='pagingbar']/a"));
        System.out.println("Total pages :" +allpages.size());
        for(int i=0; i<=(allpages.size()); i++)
            {
                for(int row=1; row<=allrows.size(); row++)
                    {
                        System.out.println("Total rows :" +allrows.size());
                        String finalLocname = driver.findElement(By.xpath("//table[@class='data-table']/tbody/tr["+row+"]/td[3]/a")).getText();
                        //System.out.println(finalLocname);
                        System.out.println("Row loop");
                        if(finalLocname.equals("hyderabadmindspace"))
                            {
                                //WebElement editbutton = driver.findElement(By.xpath("//div[@id='table']/table/tbody/tr["+row+"]/td[3]"));
                            System.out.println("Locname is "+StrLocName+" and is displayed at: "+row);
                            //editbutton.click();
                                     break;
                            }
                        /*else
                        {
                            System.out.println("Locname is not there");
                        }*/
                        allpages = driver.findElements(By.xpath("//div[@class='pagingbar']/a"));
                    }

                allpages = driver.findElements(By.xpath("//div[@class='pagingbar']/a"));
                //driver.manage().timeouts().pageLoadTimeout(5, TimeUnit.SECONDS);
                allpages.get(i).click();
                System.out.println(i);
            }
    //switch to default page
    driver.switchTo().defaultContent();
    WebElement finalLogout=driver.findElement(By.xpath("//ul[@id='option-menu']/li[3]"));
    finalLogout.click();
    //wait for home page
    wait.until(ExpectedConditions.titleIs("OrangeHRM - New Level of HR Management"));
    //Verify OrangeHRM - New Level of HR Management
            if(driver.getTitle().equals("OrangeHRM - New Level of HR Management"))
            {
                System.out.println("Signoff Sucessfull & Home Page displayed");
            }
            else
            {
                System.out.println("Failed to Signoff");
                return;
            }   


    driver.quit();


    }
}

More info: While handling pagination, in the anchor tag, pages, next and last links are there. Suppose if 2 pages are there, then anchor tag is displayed as <a>2</a>,
<a>Next</a> and <a>Last</a>, so for loop trying to click on next , but it;s not highlighted, since 2nd page is the last page, so getting an error

Please Provide solution for this

--
You received this message because you are subscribed to the Google Groups "QAPlanet" group.
To unsubscribe from this group and stop receiving emails from it, send an email to qaplanet+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "QAPlanet" group.
To unsubscribe from this group and stop receiving emails from it, send an email to qaplanet+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages