如何使用Java + Selenium WebDriver移至动态页面底部

时间:2019-06-03 13:27:03

标签: javascript java selenium selenium-webdriver

我正在尝试获取完全动态的页面中的行数。我有以下代码。但是它在一定程度上滚动并且仅获取部分元素。由于该元素是动态元素,因此无法在页面底部找到任何元素。我该如何解决这个问题?

List<WebElement> elements = driver.findElements(By.xpath(NoOfAssets));
Actions a = new Actions(driver);
a.moveToElement(elements.get(elements.size() - 1)).clickAndHold().moveByOffset(0, 1000000000).release().perform();
int noOfAssets = elements.size();
System.out.println(noOfAssets);

它仅返回40行。但是实际上还有更多的行。我想在加载行时将光标拖到页面底部,然后获取大小。

1 个答案:

答案 0 :(得分:0)

您需要nm1 <- c("City", "Continent", "Country") df1$New <- sapply(strapply(df1$Words, "([^,]+)", lst1), function(x) paste(unique(x[x %in% nm1]), collapse=",")) df1$New #[1] "City,Continent" "Country,City,Continent" #[3] "City,Country" "Country,Continent" 到页面末尾,然后找到df1 <- structure(list(Color = c("red", "blue", "red", "blue"), Letter = c("A", "A", "B", "B"), Words = c("Paris,Asia,parrot,Antarctica,North America,cat,lizard", "Panama,New York,Africa,dog,Tokyo,Washington DC,fish", "Copenhagen,bird,USA,Japan,Chicago,Mexico,insect", "Israel,Antarctica,horse,South America,North America,turtle,Brazil" )), class = "data.frame", row.names = c(NA, -4L)) 。但是,您可以使用scroll down方法向下滚动页面。尝试以下代码。让我知道去。


elements