零基础学习Selenium自动化测试--WebDriver对浏览器的操作
Posted 自动化软件测试
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了零基础学习Selenium自动化测试--WebDriver对浏览器的操作相关的知识,希望对你有一定的参考价值。
更多精彩尽在Testfan软件测试社区!ask.testfan.cn
、初始化firefox浏览器
WebDriver driver = new FirefoxDriver();
、初始化ie浏览器
WebDriver driver = new InternetExplorerDriver();
、初始化chrome浏览器
WebDriver driver = new ChromeDriver();
、访问一个指定的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/");//访问百度首页
、关闭浏览器
/** * 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启动的页面
、返回当前浏览器窗口的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();
、返回当前浏览器窗口的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();
、一些导航操作
driver.navigate().back();// 向前driver.navigate().forward();// 向后driver.navigate().refresh();// 当前页刷新driver.manage().window().maximize();// 浏览器窗口最大化
软件测试起跑群:495447734
Appium自动化测试群:534129320
接口测试开群:521192806
LoadRunner性能测试群:533981164
Selenium自动化测试群197180340
移动APP专项测试群 567341175
直接点击题目即可阅读以下好文章哦!
以上是关于零基础学习Selenium自动化测试--WebDriver对浏览器的操作的主要内容,如果未能解决你的问题,请参考以下文章
selenium-java自动化测试环境搭建中的问题以及解决方法