我正在努力使用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 :(得分:2)
如果您已经定义了webelement row
并且想在此td
中找到子/后代row
元素,则可以替换
WebDriverWait wait = new WebDriverWait(driver, 90L);
与
WebDriverWait wait = new WebDriverWait(row, 90L);
答案 1 :(得分:0)
您可以使用elementToBeClickable
代替visibilityOfElementLocated
WebDriverWait wait = new WebDriverWait(wb, 60);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("value")));
这将等待每个网页元素60秒。
答案 2 :(得分:0)
怎么样,你可以使用父元素找到子元素。
WebDriverWait wait = new WebDriverWait(driver,30);
wait.until(ExpectedConditions.visibilityOf(row.findElement(By.xpath("./td[" + columnIdx + "]"))));
答案 3 :(得分:0)
您还可以使用 presenceOfNestedElementLocatedBy 函数:
WebElement childElem = wait.until(
ExpectedConditions.presenceOfNestedElementLocatedBy(parentElem, By.xpath(xpath)));
答案 4 :(得分:0)
I was trying to figure out solution for this problem too.
The parameter to wait.Until
method is in C# just a method with following signature Func<IWebDriver, IWebElement>
(i.e. function with one parameter - the driver - returning the found element.
So instead of trying to hack the Selenium library, I don't have to call the predefined ExpectedConditions
(like ExpectedConditions.ElementExists
) methods and I can only pass function that does what I need.
var parent = ... // an element I want to start the search from
// find the element using the XPath expression starting at the parent element
wait.Until(driver => parent.FindElement(By.XPath("..."));
答案 5 :(得分:0)
这里没有一个解决方案对我有用。
对于Java或C#,我只是将其重写为单个选择器。因此,如果您想要实现的原始(不可能)代码如下所示:
var tableRow = driver.FindElement(By.CssSelector("tr:nth-child(3)"));
var wait = new WebDriverWait(tableRow , new TimeSpan(0, 0, 10));
var td = wait.until(ExpectedConditions.VisibilityOfElementLocated(By.CssSelector("td:nth-child(1)");
只需将其更改为单个选择器,然后让您的网络驱动程序等待该选择器。
var wait = new WebDriverWait(driver, new TimeSpan(0, 0, 10));
var element = wait.Until(ExpectedConditions.VisibilityOfElementLocated(By.CssSelector("tr:nth-child(3) > td:nth-child(1)")));
您也应该能够使用XPath做同样的事情