How to handle a frame in the page object model

Could you tell me how to handle frames in the page object model?

When trying with a linear script, the same thing works, but when I moved the same model of the page object, the script fails.

Currently, in my framework, below is the process that I performed:

  • Made switchTo()as a shared function and placed in a shared library.

  • On pages where a control is needed that needs to be transferred to the required frame, I called the switchTo()shared library method .

  • Further, after the control was transferred to the frame, I performed the action in the required web element. (The fact is that he cannot find a specific object)

Can someone tell me about a possible problem?

Shared library:

public void switchToFrame(int frame)
    {
        try
        {
            Driver.driver.switchTo().frame(frame);
            System.out.println("Navigated to frame with name " + frame);
        }
        catch (NoSuchFrameException e)
        {
            System.out.println("Unable to locate frame with id " + frame + e.getStackTrace());
        }
}

pages:

public void createticket(String interactionTitle,String interactionDesc,String category,String originText,String priorityText,String impactText) throws InterruptedException
    {
        switchToFrame(1);
        System.out.println("Navigated to Frame");
        waitForIdPresent("X49");
        titleEdt.sendKeys(interactionTitle);//unable to enter here
        descEdt.sendKeys(interactionDesc);
        dropDown(origipublic void createInteraction(String interactionTitle,String interactionDesc,String category,String originText,String priorityText,String impactText) throws InterruptedException
    {
        switchToFrame(1);
        System.out.println("Navigated to Frame");
        waitForIdPresent("X49");
        Driver.driver.findElement(By.id("X49")).sendKeys(interactionTitle);
        descEdt.sendKeys(interactionDesc);
        dropDown(originDropDown, originText);
}

script:

@Test
    public void createTestTicket() throws EncryptedDocumentException, InvalidFormatException, IOException, InterruptedException{

        homePage.getBtn().click();
        homePage.getLnk().click();
        interactionDetails.createTicket("test ticket","test ticket","incident","CALL","P1 / <1hour","1 - Enterprise");
    }
+4
1

, waitForIdPresent ( "id" ) .

public void waitForIdPresent(String wbId)
{
    WebDriverWait wait = new WebDriverWait(Driver.driver,20);
    wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.name(wbId)));   ‌
}

By.name By.id .

0

Source: https://habr.com/ru/post/1622166/


All Articles