在此页面上:https://www.wedoqa.com/
我必须将滑块滑动到某些引号。
(Eversave,Simply Map和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
}
}
因此,就是那些:
最佳答案
尝试使用拖放
见下面的方法
/**
* @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();
}