查找条件对象By—Selenium自动化测试指南(3)

发表于:2013-8-28 11:54

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:赵卓    来源:51Testing软件测试网

  程序清单5-12  Java代码

package Project1;
import org.openqa.selenium.*;
import org.openqa.selenium.WebDriver.*;
import org.openqa.selenium.firefox.*;
public class Project1Class {
public static void main(String[] args) {
//如果启动出现问题,可以使用System.setProperty指出firefox.exe的路径
//System.setProperty("webdriver.firefox.bin","D:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
WebDriver driver = new FirefoxDriver();
Navigation navigation = driver.navigate();
navigation.to("
http://www.baidu.com");
navigation.to("
http://www.google.com.hk");
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
navigation.back();
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
navigation.forward();
}
}

  程序清单代码执行后可以发现,程序共打开了两个页面:百度谷歌。然后,页面先后退到了第一个页面(百度),再前进到了第二个页面(谷歌)。

  5.4.3  Refresh()

  使用该方法将刷新整个页面(类似于按F5的效果),多用于执行某些操作后需要刷新的情况(例如登录后页面未自动刷新),代码如程序清单5-13或程序清单5-14所示。

  程序清单5-13  C#代码

using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
IWebDriver driver = new FirefoxDriver();
INavigation navigation = driver.Navigate();
navigation.GoToUrl("
http://www.baidu.com");
navigation.Refresh();
}
}
}

  程序清单5-14  Java代码

package Project1;
import org.openqa.selenium.*;
import org.openqa.selenium.WebDriver.*;
import org.openqa.selenium.firefox.*;
public class Project1Class {
public static void main(String[] args) {
//如果启动出现问题,可以使用System.setProperty指出firefox.exe的路径
//System.setProperty("webdriver.firefox.bin","D:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
WebDriver driver = new FirefoxDriver();
Navigation navigation = driver.navigate();
navigation.to("
http://www.baidu.com");
navigation.refresh();
}
}

51/512345>
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号