最近在学习webdriver,顺便把遇到的问题记在这里,以便日后查阅,并分享给遇到相同问题的人。
问题:运行seleniumhq.org网站上的例子。
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.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;
public class Selenium2Example {
public static void main(String[] args) {
// Create a new instance of the Firefox driver
// Notice that the remainder of the code relies on the interface,
// not the implementation.
WebDriver driver = new FirefoxDriver();
// And now use this to visit Google
driver.get("http://www.google.com");
// Alternatively the same thing can be done like this
// driver.navigate().to("http://www.google.com");
// Find the text input element by its name
WebElement element = driver.findElement(By.name("q"));
// Enter something to search for
element.sendKeys("Cheese!");
// Now submit the form. WebDriver will find the form for us from the element
element.submit();
// Check the title of the page
System.out.println("Page title is: " + driver.getTitle());
// Google's search is rendered dynamically with JavaScript.
// Wait for the page to load, timeout after 10 seconds
(new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver d) {
return d.getTitle().toLowerCase().startsWith("cheese!");
}
});
// Should see: "cheese! - Google Search"
System.out.println("Page title is: " + driver.getTitle());
//Close the browser
driver.quit();
}
}
报如下错误
Exception in thread "main" org.openqa.selenium.WebDriverException: Cannot find firefox binary in PATH. Make sure firefox is installed. OS appears to be: XP
Build info: version: '2.18.0', revision: '15704', time: '2012-01-27 17:37:17'
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.6.0_23'
看这个报错应该是firefox安装路径不是默认路径。
解决方法:方法1、最简单的重新安装firefox到默认路径。哈哈
方法2、直接用System.setPropert方法设置webdriver.firefox.bin的值,如
System.setProperty("webdriver.firefox.bin","D:\\Program Files\\Mozilla Firefox\\firefox.exe");
方法3、 用FirefoxBinary类和public FirefoxDriver(FirefoxBinary binary, FirefoxProfile profile)这个构造方法,直接上代码
File pathToFirefoxBinary = new File("D:\\Program Files\\Mozilla Firefox\\firefox.exe");
FirefoxBinary firefoxbin = new FirefoxBinary(pathToFirefoxBinary);
WebDriver driver = new FirefoxDriver(firefoxbin,null);//这里使用这个构造方法。
应该还可以在环境变量里面设置firefox的路径也可以,有兴趣的可以试一下。
注:有人可能会不知道webdriver.firefox.bin,可以看一下源码,其中
org.openqa.selenium.firefox.internal.Executable.locateFirefoxBinaryFromSystemProperty()
方法第一句
String binaryName = System.getProperty("webdriver.firefox.bin");
说明默认的时候取的就是这个值,重新设置一下。
分享到:
相关推荐
amoeba-mysql-binary-2.2.0.tar.gz amoeba-mysql-binary-2.2.0.tar.gz amoeba-mysql-binary-2.2.0.tar.gz amoeba-mysql-binary-2.2.0.tar.gzamoeba-mysql-binary-2.2.0.tar.gz amoeba-mysql-binary-2.2.0.tar.gz ...
org.openqa.selenium.WebDriverException: Cannot find firefox binary in PATH. Make sure firefox is installed. OS appears to be: VISTA Build info: version: '2.20.0', revision: '16008', time: '2012-02-27 ...
apache编译出错,它会提示./dftables: ./dftables: cannot execute binary file,这个时候我们需要编一个X86版本的dftables来取代他,这里我已经上传了一个,可以直接使用,将他拷贝到httpd-2.2.22/srclib/pcrexia下...
cef_binary_3.2623.1401.gb90a3be_windows32.7z cef_binary_3.2623.1401.gb90a3be_windows32.7z cef_binary_3.2623.1401.gb90a3be_windows32.7z
cef_binary_3.2623.1395.g3034273_windows32在WindowsXP编译的库文件和源码
eclipse如何解决no ocijdbc10 in java.library.path错误(ocijdbc9,ocijdbc8); java.lang.UnsatisfiedLinkError: no ocijdbc10 in java.library.path java.library.path 部署 ocijdbc10 Myeclipse 8.5中,web...
cef_binary_3.1547.1412_windows32.7z 浏览器开发 加载webkit 可用于 二次开发
cef_binary_3.3071.1649.g98725e6,内含x64、x86两个平台的动态库
cifar-10数据集:cifar-10-binary.tar.gz和cifar10.py等文件
cef_binary_3.2623.1395.g3034273_macosx64
cef_binary_3.3029.1619.geeeb5d7_windows32 windows cef二进制文件包
解决UE4 WebBrowser无法播放视频问题,亲测有效 UE4 CEF3 添加H264支持 使用方法: 1. 把解压后的\Resources文件夹整个复制到\Engine\Binaries\ThirdParty\CEF3\Win64,同时把Release下的除了lib文件外的所有文件...
cef_binary_3.2171.1979_windows32 含vs2005,vs2008,vs2010工程
CEF最小构建二进制库,不包含test工厂。信息如下: 1.平台:Win32 2.VS编译器版本:VS2022 3. CEF版本:115.2.3 4. Chromiun版本:115 5. 构建分支:5790 6. 编译配置:debug 和 release
cef_binary_3.2272.32.gbda8dc7_windows32.7z cef_binary_3.2272.32.gbda8dc7_windows32.7z cef_binary_3.2272.32.gbda8dc7_windows32.7zcef_binary_3.2272.32.gbda8dc7_windows32.7z cef_binary_3.2272.32.gbda8...
cef_binary_3.2357.1271.g8e0674e_windows32_官方版本.zip 这个版本官方已经无法下载 这里做个备份,这个版本也是CEF支持 npapi 的最高版本 ,最新的都不支持。
自己使用的obs中添加obs-browser插件功能时所必需的libcef_dll_wrapper.lib,cef_binary_3.2704.1434.gec3e9ed_windows32.7z可以cmake产生libcef_dll_wrapper.lib,本人亲测,使用的vs2015
ERROR Shell: Failed to locate the winutils binary in the hadoop binary path java.io.IOException: Could not locate executable null\bin\winutils.exe in the Hadoop binaries. at org.apache.hadoop.util....
groovy-binary-1.7.4.zip groovy-binary-1.7.4.zipgroovy-binary-1.7.4.zipgroovy-binary-1.7.4.zipgroovy-binary-1.7.4.zipgroovy-binary-1.7.4.zipgroovy-binary-1.7.4.zip