python-3.x - Selenium 滚动元素,页面内
问题描述
晚安朋友们!,我很难在页面的一个元素中获取所有元素,发生的情况如下:
我有一个“div”元素,里面有几条消息,字面上是一个聊天,它在滚动滚动时加载信息,只有我研究了几个关于滚动操作的教程,但我没有找到解决我问题的东西,任何人都可以给我一盏灯?一些我可以阅读的文章了解如何做到这一点。
基本上它是“无限”滚动,里面有元素,要查看我需要爬上这个滚动,我发现的另一个解决方案是通过 (Ctrl + -) 的命令或使用鼠标滚动来缩小页面ctrl + 滚动,但我一定做错了我使用了这行代码:
driver.find_element_by_tag_name ("html"). send_keys (Keys.CONTROL + "\ ue027")
什么都没发生。
我不能使用 document.body.syle.zoom,因为元素不加载
谢谢。
解决方案
最初,找到该元素然后对其进行操作,我们可以使用 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();
}
}
推荐阅读
- java - 即使密钥存在,Google Guava 缓存也每次调用加载方法
- android - 多个异步协程中调用的方法怎么只调用一次呢?
- json - 如何通过从 JMeter 中的 CSV 读取值来执行 HTTP PUT 请求?
- java - vertx如何创建eventloop线程
- autodesk-forge - 如何在 forge viewer v7 中实现自定义选择?
- composer-php - Composer:包升级到版本后显示自定义消息
- node.js - 如何使用 GitHub Actions 自动发布 Typescript 包?
- php - 路线 [proforms2.destroy2] 未定义
- html - CSS-only position-x:固定
- microsoft-teams - 在 IOS 的任务模块窗口中选择文件时,Microsoft Teams 崩溃