无法使用remoteWebdriver(例如saucelab,privateGrid)设置地理位置

时间:2018-10-23 14:03:33

标签: selenium

我正在尝试在remoteWebdriver中设置geoLocation,但是我却无法使用exception.it在ChromeDriver()中工作了

我使用的代码:

WebDriver driver =  new RemoteWebDriver(new URL(URL), caps); 
((LocationContext) driver).setLocation(new Location(12.91072, 77.60998, 100));

我遇到错误

Exception in thread "main" java.lang.ClassCastException: org.openqa.selenium.remote.RemoteWebDriver cannot be cast to org.openqa.selenium.html5.LocationContext

1 个答案:

答案 0 :(得分:1)

那古! 我之前也有此问题,我使用了增强器解决了。 在您的情况下,它将类似于:

((LocationContext) new Augmenter().augment(getDriver())).setLocation(new Location(12.91072, 77.60998, 100));

您可以在https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/remote/Augmenter.html的fo中找到更多信息