2017-04-04 77 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!让我试试这种方法。一旦这个作品,我一定会接受和关闭这个线程。 :) –