作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个场景,系统需要向上滚动到页面左侧面板中的 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();
最佳答案
Up 或 Down 到 scrollIntoView()
您必须为 引入 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/
我是一名优秀的程序员,十分优秀!