javascript - 如何向上滚动到一个元素并单击 Selenium ?

标签 javascript java selenium selenium-webdriver webdriverwait

我有一个场景,系统需要向上滚动到页面左侧面板中的 webelement,然后单击以执行其他操作。我尝试了以下方法,但都没有用。请建议:

1.

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

2.

WebElement element = driver.findElement(By.xpath("element"));
 Actions actions = new Actions(driver);
        actions.moveToElement(ele);
        actions.perform();

最佳答案

UpDownscrollIntoView() 您必须为 引入 WebDriverWait 的元素visibilityOfElementLocated() 并且您可以使用以下解决方案:

((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("element"))));

关于javascript - 如何向上滚动到一个元素并单击 Selenium ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57886380/

相关文章:

javascript - 从 HTML 文件中的脚本标签导入 js。可能的?

javascript - Pubnub - 从很多 channel 组中删除很多 channel

java - 更改 Java JInternalFrame 标题栏主题

xpath - selenium webdriver 中的高级导航

javascript - 守夜人 : Using of custom commands inside page objects

javascript - jQuery 表单提交似乎不会触发 if 语句

javascript - 为什么我的错误没有在我的快速回复中返回?

java - 迁移数据库到数据库时内存不足

java - 为什么这个GridBagLayout没有按计划出现?

java - Selenium 测试未使用 testng 在网格中并行运行