如何在 Selenium 中切换到框架?
我们可以用以下方法在 Selenium 中切换到框架 −
switchTo()defaultContent()
此方法用于在框架和父框架之间切换。重点已转移到主页。
switchTo().parentFrame()
此方法用于将控件切换到当前框架的父框架。
示例
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.concurrent.TimeUnit;
public class FrameDefault {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");
WebDriver driver = new ChromeDriver();
String url = "url with frames";
driver.get(url);
driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS);
//grabbing the first frame with the help of index
driver.switchTo().frame(0);
System.out.println("Getting the page source " + driver.getPageSource());
// switching back to the parent web page
driver.switchTo().defaultContent();
driver.quit();
}
}
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP