I\'m using Java to create selenium test cases. My system is based on portlets connected to each other. I\'m using \"selectFrame\" command to select the portlet.
I tr
We can give frame name, id, index and WebElement locator for identification
Syntax:-
driver.switchTo().frames(); // Switch to window to frame
driver.switchTo().defaultContent(); // Switch to Frame to window
If we know the total number of frames on the web page, then we can use “ index”. Index values help to easily switch between frames. An index will start from Zero i.e. if a web page has only one frame then its index will be Zero. If we don’t know the number of frames we can use “findElementBytabname()” method
Syntax: -
try
{
driver.switchTo().frame(indexnumber);
}
catch(NoSuchFrameException e)
{
System.out.println(e.getMessage());
}
We have use try and catch if now frame will not available this throw exception NoSuchFrameException()
Use name as locater to find frame Syntax: -
try
{
driver.switchTo().frame(“frameName”);
}
catch(NoSuchFrameException e)
{
System.out.println(e.getMessage());
}
Use WebElement for switching frame
Syntax: -
try
{
WebElement button=driver.findElement(By.xpath(""));
driver.switchTo().frame(button);
}
catch (NoSuchFrameException e)
{
System.out.println(e.getMessage());
}