首页 > 解决方案 > Selenium 滚动元素,页面内

问题描述

晚安朋友们!,我很难在页面的一个元素中获取所有元素,发生的情况如下:

我有一个“div”元素,里面有几条消息,字面上是一个聊天,它在滚动滚动时加载信息,只有我研究了几个关于滚动操作的教程,但我没有找到解决我问题的东西,任何人都可以给我一盏灯?一些我可以阅读的文章了解如何做到这一点。

基本上它是“无限”滚动,里面有元素,要查看我需要爬上这个滚动,我发现的另一个解决方案是通过 (Ctrl + -) 的命令或使用鼠标滚动来缩小页面ctrl + 滚动,但我一定做错了我使用了这行代码:

driver.find_element_by_tag_name ("html"). send_keys (Keys.CONTROL + "\ ue027")

什么都没发生。

我不能使用 document.body.syle.zoom,因为元素不加载

谢谢。

标签: python-3.xselenium

解决方案


最初,找到该元素然后对其进行操作,我们可以使用 Actions 类来做到这一点

public class ElementLevelScrolling {

    public static void main(String[] args)throws Exception
    {
        System.setProperty("webdriver.chrome.driver","D:\\batch250\\chromedriver_win32 (1)\\chromedriver.exe");
        ChromeDriver driver=new ChromeDriver();
        driver.manage().timeouts().implicitlyWait(5000, TimeUnit.MILLISECONDS);
        driver.manage().window().maximize();
        Thread.sleep(5000);
        driver.get("https://stackoverflow.com/questions/38653910/actions-click-script-selenium");
WebElement ele=driver.findElement(By.xpath("//ul/following-sibling::pre[@class='lang-java s-code-block hljs']"));
//to view the operations clearly moving the element into visible area
driver.executeScript("arguments[0].scrollIntoView()", ele);
Thread.sleep(3000);
Actions a=new Actions(driver);
a.sendKeys(ele,Keys.END).perform();
Thread.sleep(3000);
a.sendKeys(ele,Keys.HOME).perform();
Thread.sleep(3000);
a.sendKeys(ele,Keys.ARROW_RIGHT).perform();
Thread.sleep(3000);
a.sendKeys(ele,Keys.ARROW_LEFT).perform();
    }

}

推荐阅读