1、初始化firefox浏览器
WebDriver driver = new FirefoxDriver();
2、初始化ie浏览器
WebDriver driver = new InternetExplorerDriver();
3、初始化chrome浏览器
WebDriver driver = new ChromeDriver();
4、访问一个指定的URL
/** * Load a new web page in the current browser window. This is done using an HTTP GET operation, * and the method will block until the load is complete. This will follow redirects issued either * by the server or as a meta-redirect from within the returned HTML. Should a meta-redirect * "rest" for any duration of time, it is best to wait until this timeout is over, since should * the underlying page change whilst your test is executing the results of future calls against * this interface will be against the freshly loaded page. Synonym for * {@link org.openqa.selenium.WebDriver.Navigation#to(String)}. * * @param url The URL to load. It is best to use a fully qualified URL */ driver.get("http://www.baidu.com/");//访问百度首页
5、关闭浏览器
/** * Close the current window, quitting the browser if it's the last window currently open. */ driver.close();//关闭当前页面 /** * Quits this driver, closing every associated window. */ driver.quit();//关闭全部由driver启动的页面
6、返回当前浏览器窗口的URL(一般作为验证点)
/** * Get a string representing the current URL that the browser is looking at. * * @return The URL of the page currently loaded in the browser */ String currentUrl = driver.getCurrentUrl();
7、返回当前浏览器窗口的Title(一般作为验证点)
/** * The title of the current page. * * @return The title of the current page, with leading and trailing whitespace stripped, or null * if one is not already set */ String currentTitle = driver.getTitle();
8、一些导航操作
driver.navigate().back();// 向前 driver.navigate().forward();// 向后 driver.navigate().refresh();// 当前页刷新 driver.manage().window().maximize();// 浏览器窗口最大化
9、下一篇介绍Selenium对火狐浏览器的一些特殊处理
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!