Exported Code:
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();
}
The error is at the point where Iframe opens up. The application has an form in which some fields has buttons - and on clicking those another view opens up in pop-up (Iframe). I need to select the element from the Iframe. It's throwing an error :
// ERROR: Caught exception [ERROR: Unsupported command [selectFrame | index=1 | ]].
// ERROR: Caught exception [ERROR: Unsupported command [selectFrame | relative=parent | ]]
Are you sure it's a iFrame?
If It is try this to get iFrame "name". Will help you to focus on the right Iframe / window / tab.
Hope this will help you :)
List ele = driver.findElements(By.tagName("iframe")); System.out.println("Number of frames in a page :" + ele.size());
for(WebElement el : ele){ //Returns the Id of a frame.
System.out.println("Frame Id :" + el.getAttribute("id"));
//Returns the Name of a frame.
System.out.println("Frame name :" + el.getAttribute("name"));
}
If it's not a frame but a pop-up or window try this:
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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.