How to select a frame using selenium?

前端 未结 5 580
清酒与你
清酒与你 2020-12-19 16:40

I\'m using Java to create selenium test cases. My system is based on portlets connected to each other. I\'m using \"selectFrame\" command to select the portlet.

I tr

5条回答
  •  别那么骄傲
    2020-12-19 17:02

    We can give frame name, id, index and WebElement locator for identification

    Syntax:-

    driver.switchTo().frames(); // Switch to window to frame
    
    driver.switchTo().defaultContent();  // Switch to Frame to window
    

    If we know the total number of frames on the web page, then we can use “ index”. Index values help to easily switch between frames. An index will start from Zero i.e. if a web page has only one frame then its index will be Zero. If we don’t know the number of frames we can use “findElementBytabname()” method

    Syntax: -

       try
    {
       driver.switchTo().frame(indexnumber);
    }
      catch(NoSuchFrameException e)
    {
      System.out.println(e.getMessage());
    }
    

    We have use try and catch if now frame will not available this throw exception NoSuchFrameException()

    Use name as locater to find frame Syntax: -

     try
    {
      driver.switchTo().frame(“frameName”);
    }
      catch(NoSuchFrameException e)
    {
      System.out.println(e.getMessage());
    }
    

    Use WebElement for switching frame

    Syntax: -

      try
    {
      WebElement button=driver.findElement(By.xpath(""));
      driver.switchTo().frame(button);
    }
      catch (NoSuchFrameException e)
    {
      System.out.println(e.getMessage());
    }
    

提交回复
热议问题