我們可以給幀識別
語法姓名,ID,索引和WebElement定位: -
driver.switchTo().frames(); // Switch to window to frame
driver.switchTo().defaultContent(); // Switch to Frame to window
如果我們知道那麼我們可以使用「index」。 索引值有助於在幀之間輕鬆切換。 索引將從零開始,即如果網頁僅具有一個幀,則其索引將爲零,即 。 如果我們不知道的幀數,我們可以使用「findElementBytabname()」方法
語法: -
try
{
driver.switchTo().frame(indexnumber);
}
catch(NoSuchFrameException e)
{
System.out.println(e.getMessage());
}
我們使用try和catch如果現在幀將不提供此拋出異常NoSuchFrameException()
使用name作爲定位符來找到幀 語法: -
try
{
driver.switchTo().frame(「frameName」);
}
catch(NoSuchFrameException e)
{
System.out.println(e.getMessage());
}
使用WebElement切換幀
語法: -
try
{
WebElement button=driver.findElement(By.xpath(""));
driver.switchTo().frame(button);
}
catch (NoSuchFrameException e)
{
System.out.println(e.getMessage());
}
謝謝兩位,我真的很格萊德對您有所幫助。有用。 – 2ousy