????1. ?????????????NoClassDefFoundError??
?????????£?
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/base/Function
at com.yy.baidu.testBaidu.main(testBaidu.java:12)
Caused by: java.lang.ClassNotFoundException: com.google.common.base.Function
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 1 more
???????????
????????????????????????????Selenium????????????????????selenium-java-2.52.0.jar???????????????libs???μ????
????package
????2. ??????Firefox??·??
?????????£?
Exception in thread "main" org.openqa.selenium.WebDriverException: Cannot find firefox binary in PATH. Make sure firefox is installed. OS appears to be: WIN8_1
Build info: version: '2.52.0'?? revision: '4c2593c'?? time: '2016-02-11 19:03:33'
System info: host: 'DESKTOP-VFHU33A'?? ip: '192.168.3.115'?? os.name: 'Windows 8.1'?? os.arch: 'amd64'?? os.version: '6.3'?? java.version: '1.7.0_79'
Driver info: driver.version: FirefoxDriver
at org.openqa.selenium.firefox.internal.Executable.<init>(Executable.java:74)
at org.openqa.selenium.firefox.FirefoxBinary.<init>(FirefoxBinary.java:60)
at org.openqa.selenium.firefox.FirefoxBinary.<init>(FirefoxBinary.java:56)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:120)
at com.yy.baidu.testBaidu.main(testBaidu.java:12)
???????????
????????1. ???Firefox??????????????????°???Firefox???????
????????2. ??System.setPropert????????webdriver.firefox.bin??????磺
public class testBaidu {
public static void main(String[] args){
System.setProperty("webdriver.firefox.bin"??"D:\Mozilla Firefox\firefox.exe");
System.out.println("srart selenium ");
WebDriver driver = new FirefoxDriver();
driver.get("http://www.baidu.com");
WebElement txtbox = driver.findElement(By.id("kw"));
txtbox.sendKeys("selenium java");
WebElement btn = driver.findElement(By.id("su"));
btn.click();
System.out.println("end selenium");
}
}
????????3. ??FirefoxBinary???public FirefoxDriver(FirefoxBinary binary?? FirefoxProfile profile)???????????????????:
public class testBaidu {
public static void main(String[] args){
File pathToFirefoxBinary = new File("D:\Mozilla Firefox\firefox.exe");
FirefoxBinary firefoxbin = new FirefoxBinary(pathToFirefoxBinary);
WebDriver driver = new FirefoxDriver(firefoxbin??null);//??????????????????
System.out.println("srart selenium ");
WebDriver driver = new FirefoxDriver();
driver.get("http://www.baidu.com");
WebElement txtbox = driver.findElement(By.id("kw"));
txtbox.sendKeys("selenium java");
WebElement btn = driver.findElement(By.id("su"));
btn.click();
System.out.println("end selenium");
}
}
??????????????????webdriver.firefox.bin?????????????????
????org.openqa.selenium.firefox.internal.Executable.locateFirefoxBinaryFromSystemProperty()
?????????????
????String binaryName = System.getProperty(FirefoxDriver.SystemProperty.BROWSER_BINARY);
?????????????????????????????????????
?????????Selenium???????
????1. ???selenium?????jar??“selenium-java-2.52.0.jar”???Properties

????2. ???External location -> External File... -> ???“selenium-java-2.52.0-srcs.jar”

???????ú???????????Selenium????????