问题解决 selenium-网站demo学习-remoteDriver官方代码执行报错localhost:4444没找到
参考网站:
https://www.seleniumhq.org/docs/04_webdriver_advanced.jsp#remotewebdriver
https://www.cnblogs.com/tobecrazy/p/5020741.html
执行网站给的官方代码
import java.io.File;
import java.net.URL;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.Augmenter;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
public class Testing {
public void myTest() throws Exception {
WebDriver driver = new RemoteWebDriver(
new URL("http://localhost:4444/wd/hub"),
DesiredCapabilities.firefox());
driver.get("http://www.google.com");
// RemoteWebDriver does not implement the TakesScreenshot class
// if the driver does have the Capabilities to take a screenshot
// then Augmenter will add the TakesScreenshot methods to the instance
WebDriver augmentedDriver = new Augmenter().augment(driver);
File screenshot = ((TakesScreenshot)augmentedDriver).
getScreenshotAs(OutputType.FILE);
}
}
导致这个问题的原因是,没有开启server,解决报错的方法:
执行selenium-server-standalone.jar后,再开启server。

浙公网安备 33010602011771号