我已經瀏覽了之前的文章,並且仍然遇到問題,無法正常工作。在Java/Selenium中水平滾動的問題
我有一個小的滾動條,我需要向右移動以便可以訪問需要測試的項目。滾動條的代碼如下:
<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的值。
任何人有什麼想法?
這似乎並不奏效。我不知道如何處理該集合,有什麼方法可以將內容輸出到控制檯以查看它包含的內容嗎? – Sulteric
您可以在控制檯中運行'document.getElementsByClassName('ngscroll-scrollbar').length'並查看該定位器有多少匹配。你應該能夠在控制檯中運行這個JS,看看它是否有效。 – JeffC