我尝试执行此脚本:
public class BuyMenShirt {
public static void main(String[] args) throws InterruptedException
{
//Firefox driver setup
String driverPath = "C:\\Users\\RW\\geckodriver-master\\";
System.setProperty("webdriver.gecko.driver", driverPath + "geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("http://www.gap.com");
WebElement menlink = driver.findElement(By.id("division5063"));
menlink.click();
WebElement shirtlink = driver.findElement(By.cssSelector("a.sidebar-navigation--category--link[href=/browse/category.do?cid=15043]"));
shirtlink.click();
}
}
但是,我收到了这个错误:
Nov 01, 2016 2:10:13 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
JavaScript error: http://www.gap.com/, line 20471: TypeError: personalizationService.model.personalizationData.personalizationInfoV1.featureSelections is null
Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.
Build info: version: 'unknown', revision: '1969d75', time: '2016-10-18 09:43:45 -0700'
System info: host: 'RW-PC', ip: '192.168.0.105', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_112'
Driver info: driver.version: RemoteWebDriver
Capabilities [{rotatable=false, raisesAccessibilityExceptions=false, marionette=true, firefoxOptions={args=[], prefs={}}, appBuildId=20161019084923, version=, platform=XP, proxy={}, command_id=1, specificationLevel=0, acceptSslCerts=false, processId=1692, browserVersion=49.0.2, platformVersion=10.0, XULappId={ec8030f7-c20a-464f-9b0e-13a3a9e97384}, browserName=firefox, takesScreenshot=true, takesElementScreenshot=true, platformName=windows_nt, device=desktop}]
Session ID: 9c166d1b-3391-4ed9-8fac-3afe6d09b13f
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:622)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:368)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByCssSelector(RemoteWebDriver.java:465)
at org.openqa.selenium.By$ByCssSelector.findElement(By.java:430)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:360)
at BuyMenShirt.main(BuyMenShirt.java:27)
Caused by: java.lang.IllegalArgumentException: expected one element but was: <org.openqa.selenium.remote.ErrorCodes$KnownError@cd2dae5, org.openqa.selenium.remote.ErrorCodes$KnownError@4973813a>
at com.google.common.collect.Iterators.getOnlyElement(Iterators.java:322)
at com.google.common.collect.Iterables.getOnlyElement(Iterables.java:284)
at org.openqa.selenium.remote.ErrorCodes.toStatus(ErrorCodes.java:138)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:92)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:42)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:163)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
... 5 more
我做错了什么吗?我注意到UnreachableBrowserException
之前我遇到了一些JavaScript错误。有关系吗?