gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 11:13:23 25 4
gpt4 key购买 nike

在此页面上: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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com