【发布时间】:2017-12-08 23:29:02
【问题描述】:
我在这个页面上
https://login.alibaba.com/?spm=a2700.8293689.0.0.NdeZUw&tracelog=hd_signin
并尝试通过以下 web 元素代码访问电子邮件字段:
public static WebElement Email_Field(WebDriver driver) throws InterruptedException {
//element = (new WebDriverWait(driver, 10)).until(ExpectedConditions
//.visibilityOfElementLocated(By.xpath("//input[@id='fm-login-id']")));
element = driver.findElement(By
.xpath("//input[@id='fm-login-id']"));
while (!isDisplayed(element)) {
Thread.sleep(3000);
System.out.println("Element is not visible yet");
}
return element;
}
public static boolean isDisplayed(WebElement element) {
try {
if(element.isDisplayed())
return element.isDisplayed();
}catch (NoSuchElementException ex) {
return false;
}
return false;
}
但得到以下异常:
Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":".//*[@id='fm-login-id']"}
(Session info: chrome=59.0.3071.115)
【问题讨论】:
-
考虑更新 HTML DOM。谢谢
-
您的错误告诉您有关元素
.//*[@id='fm-login-id']但我可以在您的代码中看到//input[@id='fm-login-id']。为什么会有区别? -
他寻找的信息在
iframe中——也许框架会在之后加载。考虑等待 DomReady 事件等。咨询您的 Web 驱动程序 API -
请阅读Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers? - 总结是这不是解决志愿者的理想方式,并且可能会适得其反。请不要将此添加到您的问题中。