我已经完成了以前的帖子,但仍然遇到问题。
我有一个小滚动条我需要向右移动,以便我可以访问我需要测试的项目。滚动条的代码如下:
<div class="ngscroll-scrollbar" ng-style="styles.scrollbar" style="height:
6px; bottom: 3px; left: 3px; opacity: 0; width: 126.05px; transition:
opacity 0.3s ease-in-out 0s, border-radius 0.1s linear 0s, height 0.1s
linear 0s, bottom 0.1s linear 0s; position: absolute; cursor: default;
background: rgba(0, 0, 0, 0.6) none repeat scroll 0% 0%; border-radius: 3px;"></div>
滚动条位于容器内部,我不知道这是否是一个问题。
<div class="ngscroll-scrollbar-container" ng-show="!isTouch" ng-
style="styles.scrollbarContainer" style="bottom: 0px; left: 0px; width:
100%; height: 12px; margin-left: 0px; position: absolute; transition:
background 0.3s ease-in-out 0s; border-radius: 6px; background: transparent
none repeat scroll 0% 0%;">
这是我的代码:
WebElement scroll = driver.findElement(By.xpath("//html/body/div[2]/main/div/ui-view/ui-view/div[2]/div/div[1]/su-flight-filters/div/aside/div/section/div/div/div[2]/div/div[2]/div"));
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("document.getElementsByClassName('ngscroll-scrollbar').scrollRight += 50", "");
我没有收到任何错误,但滚动条也没有移动。我尝试过50,250和400的价值。
有人有什么想法吗?
答案 0 :(得分:0)
.getElementsByClassName()
返回一个集合。尝试
js.executeScript("document.getElementsByClassName('ngscroll-scrollbar')[0].scrollRight += 50", "");
滚动第一个匹配元素。您必须检查并确保第一场比赛是您想要的。
答案 1 :(得分:0)
使用Action类移动滑块,我发现这是一种谨慎的方式 选择X的值是否取决于滑块的宽度,如果使用for循环将指针拖到多个位置
WebElement slider = driver.findElement(By.id("slider"));
int width=slider.getSize().getWidth();
Actions move = new Actions(driver);
Action action = (Action) move.dragAndDropBy(slider, 30, 0).build();
action.perform();