import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
public static void main(String[] args) throws MalformedURLException {
// TODO Auto-generated method stub// File file = new File("C:/Users/Administrator/Desktop/chromedriver.exe");
// System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
DesiredCapabilities capabilities = new DesiredCapabilities();
// ... but only if it supports javascript
capabilities.setJavascriptEnabled(true);
// Get a handle to the driver. This will throw an exception
// if a matching driver cannot be located
// WebDriver driver = new ChromeDriver(capabilities);
// Query the driver to find out more information
DesiredCapabilities dc = DesiredCapabilities.chrome();
RemoteWebDriver driver = new RemoteWebDriver(new URL("http://10.1.0.64:9515"), dc);
// String currentWindowHandle=driver.getWindowHandle();
// driver.switchTo().window(currentWindowHandle);
// And now use it
driver.get("http://www.google.com");
}
下载想需要的软件(这个软件要看自己是什么系统的我演示的是XP的需要翻墙才能打开selenium官网)
如果你是双击打开chromedriver.exe 默认是别的机器远程连接不了你的 所以要到上参数
这样通过java 代码就可以远程打开chrome了