我从Selenide开始,想知道是否可以滚动到元素。在Seleniu中,代码如下:
Actions actions = new Actions(getWebDriver());
actions.moveToElement(loadMore).build().perform();我需要滚动到启用,因为它是不可点击的,如果它在屏幕外。
发布于 2020-02-24 19:27:45
Selenide有scrollIntoView方法,它实现JavaScript的scrollIntoView和滚动元素到特定位置:
// the top of the element will be aligned to the top.
$("").scrollIntoView(true).click();
// element will be aligned to the center.
$("").scrollIntoView("{behavior: \"instant\", block: \"center\", inline: \"center\"}").click();发布于 2020-02-24 18:40:15
这还不够吗?
actions.moveToElement(loadMore).click().build().perform()发布于 2020-02-24 19:01:15
您应该能够单击一个元素,即使它在屏幕外(确保XPath是正确的!)您可以使用actions.scrollIntoView(actions.findElement(By.xpath(xpath))
https://stackoverflow.com/questions/60381765
复制相似问题