错误:捕获到异常[错误:不支持的命令[selectFrame | 索引= 1 | ]]

导出代码:


 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 | ]]



慕标琳琳
浏览 370回答 2
2回答

炎炎设计

您确定它是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"));    }

慕森卡

如果不是框架而是弹出窗口或窗口,请尝试以下操作:字符串parentWindowHandler = driver.getWindowHandle(); //存储您的父窗口String childWindowHandler = null;&nbsp; &nbsp; Set<String> handles = driver.getWindowHandles(); // get all window handles&nbsp; &nbsp; Iterator<String> iterator = handles.iterator();&nbsp; &nbsp; while (iterator.hasNext()){&nbsp; &nbsp; &nbsp; &nbsp; childWindowHandler = iterator.next();&nbsp; &nbsp; }&nbsp; &nbsp; driver.switchTo().window(childWindowHandler); // switch to popup window&nbsp; &nbsp; // perform operations on popup&nbsp; &nbsp; try {&nbsp; &nbsp; &nbsp; &nbsp; assertTrue(isElementPresent(By.xpath("//div[@id='mainDocumentContainer']/div/div[2]/div/div/div[2]/div/table/tbody/tr/td")));&nbsp; &nbsp; &nbsp; } catch (Error e) {&nbsp; &nbsp; &nbsp; &nbsp; verificationErrors.append(e.toString());&nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; try {&nbsp; &nbsp; &nbsp; &nbsp; assertEquals("Numéro d'opération :&nbsp; &nbsp;Epicure 1", driver.findElement(By.xpath("//div[@id='mainDocumentContainer']/div/div[2]/div/div/div[2]/div/table/tbody/tr[2]/td")).getText());&nbsp; &nbsp; &nbsp; } catch (Error e) {&nbsp; &nbsp; &nbsp; &nbsp; verificationErrors.append(e.toString());&nbsp; &nbsp;//Back to main window&nbsp; &nbsp;&nbsp; &nbsp; driver.switchTo().window(parentWindowHandler);
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java