DemoUseFirefox

本文介绍了一种使用Selenium WebDriver自动化测试框架配合Firefox浏览器进行网页自动化测试的方法。通过设置Firefox配置文件并加载扩展插件,实现了对Google首页搜索功能的自动化测试。文章详细展示了如何启动带有特定配置的Firefox实例,并通过WebDriver导航到指定网站、输入搜索关键字并验证搜索结果页面。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

package demo;


import java.io.File;
import java.io.IOException;


import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.reporters.EmailableReporter;


public class DemoUseFirefox {
public static void main(String[] args) {
System.setProperty("webdriver.firefox.bin","D:\\firefox\\firefox.exe");
File file=new File(".\\res\\firebug-1.12.0a3.xpi");
FirefoxProfile firefoxProfile=new FirefoxProfile();
try {
firefoxProfile.addExtension(file);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
firefoxProfile.setPreference("extensions.firebug.currentVersion", "1.12.0a3");
WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com");
// driver.navigate().to("http://www.google.com");
WebElement element = driver.findElement(By.name("q"));
element.sendKeys("Selenium");
element.submit();
System.out.println("Page title is " + driver.getTitle());
new WebDriverWait(driver, 10).until(new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver d) {
return d.getTitle().toLowerCase().startsWith("Selenium");
}
});


System.out.println("page title is :" + driver.getTitle());
driver.quit();
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值