Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何将滑块拖动到特定字符串_Java_Selenium_Xpath_Slider - Fatal编程技术网

Java 如何将滑块拖动到特定字符串

Java 如何将滑块拖动到特定字符串,java,selenium,xpath,slider,Java,Selenium,Xpath,Slider,在本页上: 我必须滑动滑块到certan quotes。 Eversave、SimpleMap和模式发布 目前,我的代码如下所示: package test; import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.ope

在本页上: 我必须滑动滑块到certan quotes。 Eversave、SimpleMap和模式发布

目前,我的代码如下所示:

package test;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Test1 {

    public static void main(String[] args) throws InterruptedException {

        System.setProperty("webdriver.gecko.driver", "C:/Users/goran/Desktop/Alas/geckodriver.exe");
        WebDriver driver = new FirefoxDriver();
        driver.get("http://www.google.com");

        WebElement search = driver.findElement(By.name("q"));
        search.sendKeys("wedoqa.com\n");
        search.submit();

        Thread.sleep(5000);

        WebElement firstResult = driver.findElement(By.xpath("//h3[@class='r']/a"));
        firstResult.click();

        Thread.sleep(1000);

        WebElement testimonialsReferences = driver.findElement(By.id("testimonials"));
        ((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", testimonialsReferences);

        Thread.sleep(2000);     

        //HERE I NEED TO FIND ELEMENT AND SWIPE TO CERTAIN QUOTE
    }
}
所以,就是这些:

尝试使用拖放 见下面的方法

/**
 * @author mbn
 * @Date 05/01/2018
 * @Purpose This method will perform a drag and drop
 * @param fromWebElement --> element to drag from
 * @param toWebElement --> element to release to
 * @return N/A
 */
public static void dragAndDrop_Method2(WebElement fromWebElement, WebElement toWebElement) {

    Actions builder = new Actions(driver);
    Action dragAndDrop = builder.clickAndHold(fromWebElement).moveToElement(toWebElement).release(toWebElement)
            .build();
    dragAndDrop.perform();
}
还是这个方法

/**
 * @author mbn
 * @Date 05/01/2018
 * @Purpose This method will perform a drag and drop
 * @param fromWebElement --> element to drag from
 * @param toWebElement --> element to release to
 * @return N/A
 */
public static void dragAndDrop_Method3(WebElement fromWebElement, WebElement toWebElement)
        throws InterruptedException {

    Actions builder = new Actions(driver);
    builder.clickAndHold(fromWebElement).moveToElement(toWebElement).perform();
    Thread.sleep(2000);
    builder.release(toWebElement).build().perform();
}

使用滚动来实现这一点。试试下面的代码

WebElement element = driver.findElement(By.id("testimonials"));
Actions actions = new Actions(driver);
actions.moveToElement(element);
actions.perform();

希望这有帮助

你应该参考这个答案@SimonN它是安卓应用程序。。。你对我的问题有什么回答吗