我試圖通過點擊一個href加載圖像的屬性。我看到,當我點擊鏈接時,它會在所有元素內部加載一個div的頂部。如何獲取從插件像燈箱加載元素的屬性
所以我嘗試是:
js.executeScript("showModal(1,2,'"+nv+"',0);");
WebElement im =(new WebDriverWait(d, 10))
.until(new ExpectedCondition<WebElement>(){
@Override
public WebElement apply(WebDriver d) {
return d.findElement(By.id("imgView"));
}});
System.out.println(im.findElement(By.tagName("img")).getAttribute("src"));
但我檢索:
Exception in thread "main" org.openqa.selenium.TimeoutException: Timed out after 10 seconds waiting for [email protected]
Build info: version: '2.21.0', revision: '16552', time: '2012-04-11 19:08:38'
System info: os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.8', java.version: '1.6.0_33'
Driver info: driver.version: unknown
at org.openqa.selenium.support.ui.FluentWait.timeoutException(FluentWait.java:252)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:221)
at mm.Main.main(Main.java:85)
Caused by: org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"id","selector":"imgView"}
Command duration or timeout: 43 milliseconds
功能showModal
讓利給的燈箱happer並加載它裏面的圖像。
我該如何解決?有人能幫我嗎?謝謝!!
1.嘗試使用webdriver的PageSource方法來查找它是否可用。在2-3秒的Thread.sleep後執行此操作。有時xpath工作,而不是其他事情。所以,儘可能嘗試一下。 – iMatoria 2012-07-29 17:42:48