как да преместите плъзгача наляво и надясно с помощта на selenium java

Искам да плъзгам от стъпка към друга стъпка, използвайки selenium java. Препратих много публикации в stackoverflow, но нито една от тях не беше подходяща за моя случай, така мисля. По-долу е моят HTML код:

 <div style="width: 100%; height: auto; font-weight: normal; font-family: Tahoma; font-size: 8pt; font-style: normal; text-decoration: none;" class="QvSliderObject">
    <div style="width: 711px; height: 61px;">
    <canvas height="61" width="711" style="width: 711px; height: 61px;">
    <div style="position: absolute; font-size: 8pt; overflow: visible; color: rgb(54, 54, 54); font-family: Tahoma; font-weight: normal; text-align: center; left: 21px; top: 11px; width: 8px; height: 14px;">1</div>
    <div style="position: absolute; font-size: 8pt; overflow: visible; color: rgb(54, 54, 54); font-family: Tahoma; font-weight: normal; text-align: center; left: 58px; top: 11px; width: 8px; height: 14px;">2</div>
    <div style="position: absolute; font-size: 8pt; overflow: visible; color: rgb(54, 54, 54); font-family: Tahoma; font-weight: normal; text-align: center; left: 95px; top: 11px; width: 8px; height: 14px;">3</div>
    <div style="position: absolute; font-size: 8pt; overflow: visible; color: rgb(54, 54, 54); font-family: Tahoma; font-weight: normal; text-align: center; left: 132px; top: 11px; width: 8px; height: 14px;">4</div>
    <div style="position: absolute; font-size: 8pt; overflow: visible; color: rgb(54, 54, 54); font-family: Tahoma; font-weight: normal; text-align: center; left: 168px; top: 11px; width: 8px; height: 14px;">5</div>
    <div style="position: absolute; font-size: 8pt; overflow: visible; color: rgb(54, 54, 54); font-family: Tahoma; font-weight: normal; text-align: center; left: 205px; top: 11px; width: 8px; height: 14px;">6</div>
    <div style="position: absolute; font-size: 8pt; overflow: visible; color: rgb(54, 54, 54); font-family: Tahoma; font-weight: normal; text-align: center; left: 242px; top: 11px; width: 8px; height: 14px;">7</div>
    <div style="position: absolute; font-size: 8pt; overflow: visible; color: rgb(54, 54, 54); font-family: Tahoma; font-weight: normal; text-align: center; left: 279px; top: 11px; width: 8px; height: 14px;">8</div>
    <div style="position: absolute; font-size: 8pt; overflow: visible; color: rgb(54, 54, 54); font-family: Tahoma; font-weight: normal; text-align: center; left: 316px; top: 11px; width: 8px; height: 14px;">9</div>
    <div style="position: absolute; font-size: 8pt; overflow: visible; color: rgb(54, 54, 54); font-family: Tahoma; font-weight: normal; text-align: center; left: 350px; top: 11px; width: 14px; height: 14px;">10</div>
    <div style="position: absolute; font-size: 8pt; overflow: visible; color: rgb(54, 54, 54); font-family: Tahoma; font-weight: normal; text-align: center; left: 386px; top: 11px; width: 14px; height: 14px;">11</div>
    <div style="position: absolute; font-size: 8pt; overflow: visible; color: rgb(54, 54, 54); font-family: Tahoma; font-weight: normal; text-align: center; left: 423px; top: 11px; width: 14px; height: 14px;">12</div>
    <div style="position: absolute; font-size: 8pt; overflow: visible; color: rgb(54, 54, 54); font-family: Tahoma; font-weight: normal; text-align: center; left: 460px; top: 11px; width: 14px; height: 14px;">13</div>
    <div style="position: absolute; font-size: 8pt; overflow: visible; color: rgb(54, 54, 54); font-family: Tahoma; font-weight: normal; text-align: center; left: 497px; top: 11px; width: 14px; height: 14px;">14</div>
    <div style="position: absolute; font-size: 8pt; overflow: visible; color: rgb(54, 54, 54); font-family: Tahoma; font-weight: normal; text-align: center; left: 534px; top: 11px; width: 14px; height: 14px;">15</div>
    <div style="position: absolute; font-size: 8pt; overflow: visible; color: rgb(54, 54, 54); font-family: Tahoma; font-weight: normal; text-align: center; left: 571px; top: 11px; width: 14px; height: 14px;">16</div>
    <div style="position: absolute; font-size: 8pt; overflow: visible; color: rgb(54, 54, 54); font-family: Tahoma; font-weight: normal; text-align: center; left: 607px; top: 11px; width: 14px; height: 14px;">17</div>
    <div style="position: absolute; font-size: 8pt; overflow: visible; color: rgb(54, 54, 54); font-family: Tahoma; font-weight: normal; text-align: center; left: 644px; top: 11px; width: 14px; height: 14px;">18</div>
    <div style="position: absolute; font-size: 8pt; overflow: visible; color: rgb(54, 54, 54); font-family: Tahoma; font-weight: normal; text-align: center; left: 681px; top: 11px; width: 14px; height: 14px;">19</div></canvas> 
<canvas style="width: 8px; height: 12px; position: absolute; left: 646px; top: 40px; cursor: inherit;" width="8" height="12"></canvas>
    <canvas style="width: 10px; height: 12px; position: absolute; left: 696px; top: 40px;" width="10" height="12"></canvas>
    <canvas style="width: 10px; height: 12px; position: absolute; left: 5px; top: 40px;" width="10" height="12"></canvas></div></div> 

По-долу е моят Java код:

WebElement sliderLocation = driver.findElement(By.xpath("(//*[@id='64']//following::canvas)[2]"));
        // Used points class to get x and y coordinates of element.
        Point classname = sliderLocation.getLocation();
        int xcordi = classname.getX();
        int ycordi = classname.getY();
        int width = sliderLocation.getSize().getWidth();
        System.out.println(
                "Element's Position from left side of window " + xcordi + "and from right side of Window " + ycordi);
        try {
            Thread.sleep(3000);
            Actions move = new Actions(driver);
            Action action1 = (Action) move.dragAndDropBy(sliderLocation, 60, 0).build();
            action1.perform();
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }  

и изпробва всички възможни решения, предложени на това и тази връзка, но все още безполезна. Какво трябва да задам в секцията с координати. По подразбиране е на 18 и позицията на координатите му от лявата страна на прозореца е 1319, а от дясната страна на прозореца е 252.
Прикачих изображение на тази лента за превъртане. Да предположим, че искам да плъзна от 18 до 17, така че как мога да направя това? Моля, помогни ми . Лошо съм заседнал.
въведете описание на изображението тук


person Debuggerrr    schedule 28.04.2017    source източник
comment
Къде първоначално се намира показалецът? И къде искаш да се преместиш?   -  person Chandra Shekhar    schedule 28.04.2017
comment
намира се на 18 и искам да го преместя на 17 или 19 на този плъзгач   -  person Debuggerrr    schedule 28.04.2017
comment
кой е твоят //*[@id='64'] в html?   -  person Edwin    schedule 28.04.2017
comment
това е курсорът върху плъзгача, който искам да плъзна   -  person Debuggerrr    schedule 28.04.2017


Отговори (1)


Следният код ще премести вашия плъзгач до скала "17":

WebElement sliderLocation = driver.findElement(By.xpath("(//*[@id='64']//following::canvas)[2]"));
  WebElement elem17 = driver.findElement(By.xpath("//*[@id='64']/div[2]/div[1]/div/div[17]"));

Actions action = new Actions(driver);
action.clickAndHold(sliderLocation).moveToElement(elem17).release(sliderLocation).build().perform();

Предполагам, че sliderLocation се отнася до този елемент въведете описание на изображението тук

person Kushal    schedule 28.04.2017
comment
Не, не се премества към 17 .sliderLocation е курсорът върху плъзгача, който искам да преместя и xpath е правилен - person Debuggerrr; 28.04.2017
comment
Бихте ли споделили HTML за въпросния плъзгач - person Kushal; 28.04.2017
comment
Не извежда никаква грешка и добавих 3 реда на платното в края на html кода, където първият ред на платното е за курсора върху плъзгача, за който създадох персонализиран xpath с помощта на firebug - person Debuggerrr; 28.04.2017
comment
възможно ли е да споделите URL адреса си? - person Kushal; 28.04.2017
comment
Бихте ли споделили резултата от elem17.getText((); - person Kushal; 28.04.2017
comment
сега дава тази грешка org.openqa.selenium.NoSuchElementException: Не може да се намери елемент: {method:css selector,selector:div.QvSliderObject canvas div:nth-child(17)} Продължителност на командата или изчакване: 160,08 секунди при sun.reflect .NativeConstructorAccessorImpl.newInstance0(Собствен метод) - person Debuggerrr; 29.04.2017
comment
Това може да се дължи на факта, че елементът може да е разположен върху рамка или нещо подобно; този локатор е правилен според необходимия HTML. - person Kushal; 29.04.2017
comment
няма нищо като рамка в моя html. Значи има ли решение за това? - person Debuggerrr; 29.04.2017
comment
Отидете до chrome > developer options > console >type $x("div.QvSliderObject canvas div:nth-child(17)") и натиснете enter; какъв е резултата - person Kushal; 29.04.2017
comment
показва невалиден xpath израз, но е персонализиран с помощта на firebug в mozilla - person Debuggerrr; 02.05.2017
comment
Така че целият проблем се дължи на невалиден xpath, моля, предоставете xpath, предоставен от firebug - person Kushal; 02.05.2017
comment
.//*[@id='64']/div[2]/div[1]/div/div[17] това е xpath за 17 . - person Debuggerrr; 02.05.2017
comment
Исках xpath за elem17? - person Kushal; 02.05.2017
comment
Отидете на chrome › developer options › console › type $$(div.QvSliderObject canvas div:nth-child(17)) и натиснете enter; какъв е резултата - person Kushal; 02.05.2017
comment
Също $$(#64 div›div›div div:nth-child(17)) - person Kushal; 02.05.2017
comment
редактирайте отговора си по-горе с този ред за елемент 17 и аз ще го маркирам като приет, защото проблемът ми е решен сега :) мога да се движа надясно и наляво от неговия конкретен Xpath WebElement elem17 = driver.findElement(By.xpath(//*[ @id='64']/div[2]/div[1]/div/div[17])); благодаря много @kushal :) - person Debuggerrr; 02.05.2017
comment
изтрий другия си отговор kushal :) - person Debuggerrr; 02.05.2017
comment
Да, скоро ще го направя. - person Kushal; 02.05.2017