ERROR: Caught exception [ERROR: Unsupported command [selectFrame | index=1 | ]] while exporting code from Selenium IDE to Webdriver
ERROR: Caught exception [ERROR: Unsupported command [selectFrame | index=1 | ]] while exporting code from Selenium IDE to Webdriver
导出代码:
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) 中打开。我需要 select 来自 Iframe 的元素。它抛出一个错误:
// ERROR: Caught exception [ERROR: Unsupported command [selectFrame | index=1 | ]].
// ERROR: Caught exception [ERROR: Unsupported command [selectFrame | relative=parent | ]]
您确定这是 iFrame 吗?
如果是尝试此方法获取 iFrame "name"。将帮助您专注于正确的 iframe / window / 标签。
希望这对您有所帮助:)
List ele = driver.findElements(By.tagName("iframe"));
System.out.println("Number of frames in a page :" + ele.size());
for(WebElement el : ele){
//Returns帧的Id。
System.out.println("Frame Id :" + el.getAttribute("id"));
//Returns the Name of a frame.
System.out.println("Frame name :" + el.getAttribute("name"));
}
如果不是框架而是弹出窗口或window试试这个:
String parentWindowHandler = driver.getWindowHandle(); // Store your parent window
String 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);
导出代码:
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) 中打开。我需要 select 来自 Iframe 的元素。它抛出一个错误:
// ERROR: Caught exception [ERROR: Unsupported command [selectFrame | index=1 | ]].
// ERROR: Caught exception [ERROR: Unsupported command [selectFrame | relative=parent | ]]
您确定这是 iFrame 吗?
如果是尝试此方法获取 iFrame "name"。将帮助您专注于正确的 iframe / window / 标签。
希望这对您有所帮助:)
List ele = driver.findElements(By.tagName("iframe")); System.out.println("Number of frames in a page :" + ele.size());
for(WebElement el : ele){ //Returns帧的Id。
System.out.println("Frame Id :" + el.getAttribute("id"));
//Returns the Name of a frame.
System.out.println("Frame name :" + el.getAttribute("name"));
}
如果不是框架而是弹出窗口或window试试这个:
String parentWindowHandler = driver.getWindowHandle(); // Store your parent window String 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);