如何滑动水平滑块。我试图滚动滑块,但对我不起作用。我使用Java的代码如下:
我无法正确滑动滑块,无论输入什么值,它都会滑动到固定的pomit onlt,当前滑块值为2,并且在运行时它将滑动到3
WebElement slideFrom = driver.findElement(By.xpath("//*[@id=\"radius\"]/div[2]/div/span"));
Actions move = new Actions(driver);
move.moveToElement(slideFrom).clickAndHold().moveByOffset(370, 470).release().perform();
Thread.sleep(2000);
HTML代码:滑块
<span class="irs js-irs-0 irs-with-grid"><span class="irs"><span class="irs-line" tabindex="-1"><span class="irs-line-left"></span><span class="irs-line-mid"></span><span class="irs-line-right"></span></span><span class="irs-min" style="visibility: visible;">0.5</span><span class="irs-max" style="visibility: visible;">20</span><span class="irs-from" style="visibility: hidden;">0</span><span class="irs-to" style="visibility: hidden;">0</span><span class="irs-single" style="left: 26.064%;">2</span></span><span class="irs-grid" style="width: 95.5679%; left: 2.11607%;"><span class="irs-grid-pol" style="left: 0%"></span><span class="irs-grid-text js-grid-text-0" style="left: 0%; margin-left: -2.63158%;">0.5</span><span class="irs-grid-pol small" style="left: 6.060606061%"></span>
<span class="irs-grid-pol small" style="left: 3.03030303%"></span><span class="irs-grid-pol" style="left: 9.090909091%"></span>
<span class="irs-grid-text js-grid-text-1" style="left: 9.09091%; visibility: visible; margin-left: -1.52355%;">1</span><span class="irs-grid-pol small" style="left: 15.151515152%"></span><span class="irs-grid-pol small" style="left: 12.121212121%"></span>
<span class="irs-grid-pol" style="left: 18.181818182%"></span><span class="irs-grid-text js-grid-text-2" style="left: 18.1818%; visibility: visible; margin-left: -2.49307%;">1.5</span><span class="irs-grid-pol small" style="left: 24.242424243%"></span><span class="irs-grid-pol small" style="left: 21.212121212%"></span><span class="irs-grid-pol" style="left: 27.272727273%"></span><span class="irs-grid-text js-grid-text-3" style="left: 27.2727%; visibility: visible; margin-left: -1.52355%;">2</span><span class="irs-grid-pol small" style="left: 33.333333334%"></span>
<span class="irs-grid-pol small" style="left: 30.303030303%"></span><span class="irs-grid-pol" style="left: 36.363636364%"></span>
<span class="irs-grid-text js-grid-text-4" style="left: 36.3636%; margin-left: -2.63158%;">2.5</span><span class="irs-grid-pol small" style="left: 42.424242425%"></span><span class="irs-grid-pol small" style="left: 39.393939394%"></span><span class="irs-grid-pol" style="left: 45.454545455%"></span><span class="irs-grid-text js-grid-text-5" style="left: 45.4545%; visibility: visible; margin-left: -1.52355%;">3</span><span class="irs-grid-pol small" style="left: 51.515151516%"></span><span class="irs-grid-pol small" style="left: 48.484848485%"></span><span class="irs-grid-pol" style="left: 54.545454546%"></span><span class="irs-grid-text js-grid-text-6" style="left: 54.5455%; visibility: visible; margin-left: -2.49307%;">3.5</span><span class="irs-grid-pol small" style="left: 60.606060607%"></span>
<span class="irs-grid-pol small" style="left: 57.575757576%"></span><span class="irs-grid-pol" style="left: 63.636363637%"></span><span class="irs-grid-text js-grid-text-7" style="left: 63.6364%; visibility: visible; margin-left: -1.52355%;">4</span><span class="irs-grid-pol small" style="left: 69.696969698%"></span><span class="irs-grid-pol small" style="left: 66.666666667%"></span><span class="irs-grid-pol" style="left: 72.727272728%"></span><span class="irs-grid-text js-grid-text-8" style="left: 72.7273%; margin-left: -2.49307%;">4.5</span>
<span class="irs-grid-pol small" style="left: 78.787878789%"></span><span class="irs-grid-pol small" style="left: 75.757575758%"></span>
<span class="irs-grid-pol" style="left: 81.818181819%"></span><span class="irs-grid-text js-grid-text-9" style="left: 81.8182%; visibility: visible; margin-left: -1.52355%;">5</span><span class="irs-grid-pol small" style="left: 87.87878788%"></span><span class="irs-grid-pol small" style="left: 84.848484849%"></span><span class="irs-grid-pol" style="left: 90.90909091%"></span><span class="irs-grid-text js-grid-text-10" style="left: 90.9091%; visibility: visible; margin-left: -2.21607%;">10</span><span class="irs-grid-pol" style="left: 100%"></span><span class="irs-grid-text js-grid-text-11" style="left: 100%; visibility: visible; margin-left: -2.21607%;">20</span></span>
<span class="irs-bar" style="left: 2.21607%; width: 26.064%;"></span><span class="irs-bar-edge"></span>
<span class="irs-shadow shadow-single" style="display: none;"></span><span class="irs-slider single" style="left: 26.064%;"></span></span><input type="text" id="radiussearchform-radius" class="radius-search filter-property irs-hidden-input" name="RadiusSearchForm[radius]" value="2" readonly="">
我希望滑动滑块并保持指定的值
滑块图像: