【发布时间】:2016-10-01 03:56:06
【问题描述】:
代码在我的localhost(win10) 中运行良好,但在Linux(64bt) 上出现异常错误:
org.openqa.selenium.NoSuchElementException: {"errorMessage":"无法找到 id 为 'magix_vf_root' 的元素","request":{"headers":{"Accept":"application/json, image/png ","Connection":"Keep-Alive","Content-Length":"38","Content-Type":"application/json; charset=utf-8","Host":"localhost:12709"} ,"httpVersion":"1.1","method":"POST","post":"{\"using\":\"id\",\"value\":\"magix_vf_root\"}"," url":"/element","urlParsed":{"anchor":"","query":"","file":"element","directory":"/","path":"/element ","relative":"/element","port":"","host":"","password":"","user":"","userInfo":"","authority": "","protocol":"","source":"/element","queryKey":{},"chunks":["element"]},"urlOriginal":"/session/350bd6e0-8784-11e6 -b57c-35629091c8a9/元素"}} 命令持续时间或超时:60.32 秒
这是我的代码:
public static void testPhantomjs() throws IOException{
DesiredCapabilities caps = new DesiredCapabilities();
caps.setJavascriptEnabled(true);
caps.setCapability("takesScreenshot", true);
caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, "F:\\selenium\\phantomjs.exe");
//caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, "/opt/phantomjs");
//System.setProperty("webdriver.chrome.driver", "F:\\selenium\\phantomjs.exe");
WebDriver d = new PhantomJSDriver(caps);
try{
//d.manage().timeouts().setScriptTimeout(20L, TimeUnit.SECONDS);
d.manage().timeouts().implicitlyWait(60L, TimeUnit.SECONDS);
d.get("http://www.alimama.com/member/login.htm?forward=http%3A%2F%2Fpub.alimama.com%2Fmyunion.htm");
d.manage().window().maximize();
d = d.switchTo().frame(d.findElement(By.name("taobaoLoginIfr")));
//WebElement quick = new WebDriverWait(d, 10).until(ExpectedConditions.visibilityOfElementLocated(By.id("J_Quick2Static")));
//new Actions(d).moveToElement(quick).click().perform();
//quick.click();
d.findElement(By.id("J_Quick2Static")).click();
//d.findElement(By.id("TPL_username_1")).clear();
d.findElement(By.id("TPL_username_1")).sendKeys("username");
//d.findElement(By.id("TPL_password_1")).clear();
d.findElement(By.id("TPL_password_1")).sendKeys("password");
getScreenshot(d, "1");
d.findElement(By.id("J_SubmitStatic")).click();
//d.switchTo().defaultContent();
getScreenshot(d , "2");
d.findElement(By.id("magix_vf_root"));
getScreenshot(d , "3");
Set<Cookie> cookies = d.manage().getCookies();
StringBuffer sb = new StringBuffer();
for (Cookie cookie : cookies) {
sb.append(cookie.getName() + "=" + cookie.getValue() + ";");
}
System.out.println("cookiestr:" + sb.toString());
}catch(Exception e){
e.printStackTrace();
}finally{
getScreenshot(d, "finally");
d.quit();
}
}
结果信息:
【问题讨论】:
标签: linux selenium selenium-webdriver phantomjs