Reputation: 31
When trying to Switch to the seconf frame packageFrame, getting the following exception.
Exception in thread "main" org.openqa.selenium.NoSuchFrameException: No frame element found by name or id packageFrame is displayed.
Please find my code below,
System.setProperty("webdriver.chrome.driver", "E://MyEclipse//jars//chromedriver//chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://demo.guru99.com/selenium/deprecated.html");
driver.switchTo().frame("classFrame");
driver.findElement(By.linkText("Deprecated")).click();
driver.switchTo().frame("packageFrame");
driver.findElement(By.xpath("//*[contains(text(),'AbstractWebDriverEventListener')]")).click();
Upvotes: 0
Views: 1886
Reputation: 70
Focusing to frame is based of the DOM structure. 1. This code is used to focus to parent frame. Which means the driver instance moves the focus from current frame to patent frame.
WebDriver.switchTo().parentFrame();
2. This code is used to focus to root(about the root frame). Which means the driver instance moves the focus from current frame to out of the all frames.
WebDriver.switchTo().defaultContent();
3. This code is used to focus to child frames. Which means the driver instance moves the focus from current frame to child frames. Here you can pass parameter as frame name, frame id, frame element and index. if index is 0, then it is first child frame.
WebDriver.switchTo().frame(parameter);
Note: If u want to focus sibling frames, first you have to focus to parent frame and then only possible to focus next.
Upvotes: 1
Reputation: 4739
First come to parent frame and then go to second frame
//Switch to parent window
driver.switchTo().defaultContent();
//switching to frame 2 i.e. packageFrame
driver.switchTo().frame("packageFrame");
//locate AbstractWebDriverEventListener and click
driver.findElement(By.xpath("//[contains(text(),'AbstractWebDriverEventListener')]")).click();
Upvotes: 1
Reputation: 5347
You can use driver.switchTo().defaultContent() method before switching to second frame as given below.
//launch browser
System.setProperty("webdriver.chrome.driver", "E://MyEclipse//jars//chromedriver//chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://demo.guru99.com/selenium/deprecated.html");
driver.switchTo().frame("classFrame"); //switching to frame 1
driver.findElement(By.linkText("Deprecated")).click();
driver.switchTo().defaultContent(; //swithc to parent window
driver.switchTo().frame("packageFrame");//switching to frame 2
driver.findElement(By.xpath("//*[contains(text(),'AbstractWebDriverEventListener')]")).click();
This may works for you.
Upvotes: 1