错误:捕获到异常[错误:不支持的命令[selectFrame |索引= 1 | ]]将代码从Selenium IDE导出到Webdriver

时间:2018-07-04 11:55:51

标签: java selenium-webdriver selenium-ide

导出的代码:

 public void testUntitledTestCase() throws Exception {

    driver.get("URL");

    driver.findElement(By.xpath("//button[@id='add-items']")).click();

    driver.findElement(By.id("item_title")).sendKeys("Automation");

    driver.findElement(By.id("item_cat_id")).click();

    // ERROR: Caught exception [ERROR: Unsupported command [selectFrame | index=1 | ]]

    driver.findElement(By.linkText("Cat1")).click();

    // ERROR: Caught exception [ERROR: Unsupported command [selectFrame | relative=parent | ]]

    driver.findElement(By.xpath("//button[@id='item-save']"").click();
  }

错误发生在Iframe打开的位置。该应用程序具有一种形式,其中某些字段具有按钮-单击这些其他视图时,将在弹出窗口(Iframe)中打开。我需要从iframe中选择元素。抛出错误:

// ERROR: Caught exception [ERROR: Unsupported command [selectFrame | index=1 | ]].
// ERROR: Caught exception [ERROR: Unsupported command [selectFrame | relative=parent | ]]

2 个答案:

答案 0 :(得分:1)

您确定它是iFrame吗?

如果是这样,请尝试获取iFrame“名称”。将帮助您专注于正确的iframe /窗口/标签。

希望这会对您有所帮助:)

  

列表ele = driver.findElements(By.tagName(“ iframe”));           System.out.println(“页面中的帧数:” + ele.size());

for(WebElement el:ele){           //返回框架的ID。

        System.out.println("Frame Id :" + el.getAttribute("id"));
      //Returns the Name of a frame.

        System.out.println("Frame name :" + el.getAttribute("name"));
    }

答案 1 :(得分:0)

如果不是框架而是弹出窗口或窗口,请尝试以下操作:

  

String parentWindowHandler = driver.getWindowHandle(); //存储您的父窗口           字符串childWindowHandler = null;

    Set<String> handles = driver.getWindowHandles(); // get all window handles
    Iterator<String> iterator = handles.iterator();
    while (iterator.hasNext()){
        childWindowHandler = iterator.next();
    }
    driver.switchTo().window(childWindowHandler); // switch to popup window


    // perform operations on popup

    try {
        assertTrue(isElementPresent(By.xpath("//div[@id='mainDocumentContainer']/div/div[2]/div/div/div[2]/div/table/tbody/tr/td")));
      } catch (Error e) {
        verificationErrors.append(e.toString());
      }
      try {
        assertEquals("Numéro d'opération :   Epicure 1", driver.findElement(By.xpath("//div[@id='mainDocumentContainer']/div/div[2]/div/div/div[2]/div/table/tbody/tr[2]/td")).getText());
      } catch (Error e) {
        verificationErrors.append(e.toString());


   //Back to main window   

    driver.switchTo().window(parentWindowHandler);