java - 如何将 slider 拖动到特定字符串

标签 java selenium xpath slider

在此页面上:https://www.wedoqa.com/ 我必须将 slider 滑动到某些引号。 (Eversave、Simplymap 和 Pattern 发布)

现在我的代码如下所示:

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
    }
}

所以,就是这些: enter image description here

enter image description here

enter image description here

enter image description here

最佳答案

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

/**
 * @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();
}

关于java - 如何将 slider 拖动到特定字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50455764/

相关文章:

java - GUI学生申请表

java - sun.net.www.protocol.https.HttpsURLConnectionImpl 无法转换为 sun.net.www.protocol.http.HttpURLConnection

selenium - 在 Jenkins HTML Publisher 上播放视频的问题

java - Selenium 网络驱动程序 : how to use xpath filter?

ios - 使用hpple从html中获取表格数据

java - Feed通过html tidy渲染jsp页面

java - 如何在运行时语言 (Java) 中向 Birt 中插入图像

java - 谢尔宾斯基三角 java

python - 如何通过 Selenium 和 Python 将文本发送到搜索字段

xml - 具有单独父元素子元素条件的 XPath 表达式