我正在尝试使用PhantomJS Driver进行头部测试。问题是:无法处理重定向的URLS ex URL:https://gmail.com
环境: phantomjs-1.9.7-windows ; phantomjsdriver:1.0.4 ; junit:4.8.1 ; selenium-server:2.39.0
控制台:
Feb 4, 2014 4:42:34 AM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
INFO: executable: C:\Users\xprk067\softwares\phantomjs-1.9.7-windows\phantomjs.exe
Feb 4, 2014 4:42:34 AM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
INFO: port: 7070
Feb 4, 2014 4:42:34 AM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
INFO: arguments: [--webdriver=7070]
Feb 4, 2014 4:42:34 AM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
INFO: environment: {}
PhantomJS is launching GhostDriver...
[ERROR - 2014-02-04T10:42:34.998Z] GhostDriver - main.fail - {"message":"Could not start Ghost Driver","line":82,"sourceId":79376088,"sourceURL":":/ghostdriver/main.js","stack":"Error: Could not start Ghost Driver\n at :/ghostdriver/main.js:82","stackArray":[{"sourceURL":":/ghostdriver/main.js","line":82}]}
OUTPUT:blank
这是我用过的代码
public class PhantamJS{
private WebDriver driver;
private WebDriver driver2;
@Test
public void test(){
**PhantomJSDriver to get the current URL : Not Working**
Proxy proxy = new Proxy();
PhantomJSDriverService driverService = new PhantomJSDriverService.Builder()
.usingPhantomJSExecutable(new File("C:\\Users\\amar\\softwares\\phantomjs-1.9.7-windows\\phantomjs.exe"))
.usingPort(7070)
.build();
final DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.PROXY, proxy);
driver2 = new PhantomJSDriver(driverService, capabilities);
driver2.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver2.get("https://gmail.com");
String currentURL2 = driver2.getCurrentUrl();
System.out.println("OUTPUT" + currentURL2 );
}
}
答案 0 :(得分:1)
您需要使用window.setTimeout进行解决,并在请求url时增加参数。