[英]phantomjs exception error on Linux(64bit) org.openqa.selenium.NoSuchElementException
the code runs well in my localhost(win10)
, but exception error on Linux(64bt)
: 代码在我的
localhost(win10)
运行良好,但是在Linux(64bt)
上出现异常错误:
org.openqa.selenium.NoSuchElementException: {"errorMessage":"Unable to find element with 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/element"}} Command duration or timeout: 60.32 seconds
org.openqa.selenium.NoSuchElementException:{“ errorMessage”:“无法找到ID为'magix_vf_root'的元素,” request“:{” headers“:{” Accept“:” application / json,image / png“,” Connection“:”保持活动“,” Content-Length“:” 38“,” Content-Type“:” application / json; charset = utf-8“,” Host“:” localhost:12709“},” httpVersion “:” 1.1“,”方法“:” 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 / element“}}命令持续时间或超时:60.32秒
Here is my code: 这是我的代码:
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();
}
}
And the result message: 结果消息:
the code runs well in my localhost(win10),but exception error on Linux(64bt): org.openqa.selenium.NoSuchElementException: {"errorMessage":"Unable to find element with id 'magix_vf_root'"
该代码在我的本地主机(win10)上运行良好,但是在Linux(64bt)上出现异常错误:org.openqa.selenium.NoSuchElementException:{“ errorMessage”:“无法找到ID为'magix_vf_root'的元素”
It looks like timing issue, you should try using WebDriverWait
to wait until element is present on the DOM
as below :- 看来是时间问题,您应该尝试使用
WebDriverWait
等待元素出现在DOM
,如下所示:
WebElement quick = new WebDriverWait(d, 10).until(ExpectedConditions.presenceOfElementLocated(By.id("magix_vf_root")));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.