gpt4 book ai didi

java - Selenium - 在模式窗口中处理动态数据

转载 作者:太空宇宙 更新时间:2023-11-04 10:33:57 25 4
gpt4 key购买 nike

场景:模式窗口中显示项目列表,并带有星号图标,可将所选项目添加到 Collection 夹。我需要将一些项目(随机)添加到 Collection 夹中,并验证它们是否已添加到 Collection 夹中。

我的方法:我使用 Webelements 列表过滤掉未加星标的项目,然后单击星形图标(通过使用索引)将其添加到列表中。下面给出的是代码片段

Actions obj = new Actions(driver);
obj.click(nonFavoriteInstruments.get(1)).build().perform();
obj.click(nonFavoriteInstruments.get(2)).build().perform();

问题:在模态中,有一个不需要始终单击的滚动条。如果不喜欢的过滤器项目不在显示 View 中,我需要向下滚动。

enter image description here

有人可以帮我处理这种情况吗?提前致谢。

此外,请注意,即使将项目添加到 Collection 夹中,它们也会保持在相同的位置。它不会在模态窗口中向上移动。

~谢谢!

最佳答案

这将滚动直到元素出现在 View 中:

WebElement element = driver.findElement(By.id("id_of_element"));
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", element);
Thread.sleep(500);

或者您可以使用操作

WebElement element = driver.findElement(By.id("my-id"));
Actions actions = new Actions(driver);
actions.moveToElement(element);
actions.perform();

关于java - Selenium - 在模式窗口中处理动态数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49681567/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com