我们可以看到只有18行 当我滚动条时(在图1中用蓝色箭头显示)html源代码 显示了另外18行,因为只有18行可以容纳在对话框中。 现在,我想将栏滚动到最后,然后选择框的最后一行。 我该怎么做?
我尝试使用
public void waitForElement()
{
//IJavaScriptExecutor je = (IJavaScriptExecutor)StaticDriver.driver;
//IWebElement element = StaticDriver.driver.FindElement(By.XPath("(//*[@class= 'slick-cell l0 r0 row_62 cid_col_0']//div)//following-sibling::div"));
//je.ExecuteScript("arguments[0].scrollIntoView(true);", element);
var element = StaticDriver.driver.FindElement(By.XPath("(//*[@class= 'slick-cell l0 r0 row_62 cid_col_0']//div)//following-sibling::div"));
Actions actions = new Actions(StaticDriver.driver);
actions.MoveToElement(element);
actions.Perform();
}
// that xpath is the element of last row.
但是我遇到了错误Element count be found
如何滚动到最后一个并找到元素?
最后一个元素的View和html源代码为:
答案 0 :(得分:2)
尝试使用JavaScript执行器滚动到页面结尾:
js.executeScript("window.scrollTo(0, document.body.scrollHeight)");
答案 1 :(得分:0)
上面的答案应该起作用,以防您要滚动到该元素时可以使用以下命令:-
IWebElement element = driver.FindElement(by);
((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].scrollIntoView(true);", element);