2017-04-04 75 views
0

我用的visibilityOfElementLocated如何等待子元素的visibilityOfElementLocated?

語法我有一個錶行的元素掙扎,現在我需要在此行中搜索一個元素像row.findElement(xxx)

下面是語法,我們使用的定位元素(父)直接在頁

WebDriverWait wait = new WebDriverWait(driver, 90L); 
WebElement data=wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath 
       ("./td[" + columnIdx + "]"); 

所以問題是如何使用上面等待tableRow? (例如tableRow。(wait.until))

謝謝!

回答

0

可以代替使用elementToBeClickablevisibilityOfElementLocated

WebDriverWait wait = new WebDriverWait(wb, 60); 
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("value"))); 

這將等待每一個網頁元素60秒。

+0

謝謝Anuj。但這不是我正在尋找的。我有一個固定的父元素。現在我想在這個父元素上等待子元素。 –

+0

你能提供這個html嗎? –

+0

對不起,但不行。類似於@Andersson的下面的答案。這就像父 - > wait.until.condition.child-locator –

0

如果您已經定義webelement row,你想找到這個row裏面的孩子/後代td元素可以代替

WebDriverWait wait = new WebDriverWait(driver, 90L); 

WebDriverWait wait = new WebDriverWait(row, 90L); 
+0

我不認爲WebDriverWait構造函數支持這一個..我試過但得到了,不能應用編譯器錯誤 –

+0

我沒有嘗試與'Java',但這是它如何與'Python'協同工作......你能用完整的代碼更新你的票嗎?顯示你是如何實現'WebDriverWait(row,90L);' – Andersson

+0

謝謝安德森的指導。我還沒有實現它,因爲我停留在語法上。如果我能夠在這裏解釋我的要求,我認爲我們不需要完整的代碼。讓我知道你是否需要對此進行澄清 –

0

這個怎麼樣,你可以找到使用父元素的子元素。

WebDriverWait wait = new WebDriverWait(driver,30); 
    wait.until(ExpectedConditions.visibilityOf(row.findElement(By.xpath("./td[" + columnIdx + "]")))); 
+0

這是我在想什麼。我想這將有望解決我的StaleElementReferenceException。將試一試!謝謝Gaurang隊友 –

+0

@ShekharSwami這是你應該做的,一旦你找到你的答案http://stackoverflow.com/help/someone-answers –

+0

是啊@GaurangShah!讓我試試這種方法。一旦這個作品,我一定會接受和關閉這個線程。 :) –