Search code examples
seleniumiframeautomationpega

Access data of a frame from another frame in Selenium


I am automating a web application based on PEGA for my organization using Selenium. A PEGA application has lots of iframes.

My problem is: I have a table on Page A displaying some search results. If I select any one of the rows, then click Submit button, next page is loaded. Page B (next page) contains a dropdown which I have to validate that it contains the exact same values which I selected from the table on Page A.

All my other automation scenarios work perfectly fine by switching into frames and then into default content. But, this scenario does not allow me to pass onto the search result on Page A (using ArrayList) to Page B (containing another ArrayList). I have to compare these two Arraylists, the only issue is the passing/accessing of data across frames.


Solution

  • Assuming you are using the Selenium Java Client we can take help of the Java Collection to compare 2 ArrayList. Here is a sample prototype for your reference:

    //Switch to the first frame
    driver.switchTo().frame("firstFrame"); 
    //Collect the WebElements, retrive the text and save in a List
    List<WebElement> team_member = driver.findElements(By.xpath("xpathA"));
    List<String> mem_name_list = new ArrayList<String>();
    for (WebElement member:team_member)
    {
        String memeber_name = member.getAttribute("innerHTML");
        mem_name_list.add(memeber_name);
    }
    //Switch back to Top Window
    driver.switchTo().defaultContent();
    //Switch to the second frame
    driver.switchTo().frame("secondFrame");
    //Collect the WebElements, retrive the text and save in a List
    List<WebElement> team_member_images = driver.findElements(By.xpath("//main[@id='content']//div[@class='team-members']/div[@class='team-member']/div[@class='team-member-portrait']/img"));
    List<String> mem_image_list = new ArrayList<String>();
    for (WebElement image_link:team_member_images)
    {
        String memebr_image = image_link.getAttribute("src");
        mem_image_list.add(memebr_image);
    }
    //Switch back to Top Window
    driver.switchTo().defaultContent();
    //Assert the two List<String> in a loop