Kar*_*ani 1 java testng selenium-webdriver
我想移动滑块左侧的滑块。但是,selenium webdriver 将其移动到右侧,但不会移动到左侧。我想将滑块移动到滑块总宽度的 25%。我在 java 1.8 和 selenium 2.44 中使用下面给出的代码。我已经尝试了使用向上、向下、向左、向右箭头键的所有选项,但仍然无法实现。
我将不胜感激您的投入。
package RandD;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Action;
import org.openqa.selenium.interactions.Actions;
public class test{
static WebDriver driver;
public static void main(String[] args)
{
driver = new FirefoxDriver();
driver.get("http://jqueryui.com/slider/");
driver.switchTo().frame(0);
slider();
}
public static void slider(){
WebElement slider = driver.findElement(By.id("slider"));
int width=slider.getSize().getWidth();
Actions move = new Actions(driver);
org.openqa.selenium.interactions.Action action = move.dragAndDropBy(slider, ((width*25)/100), 0).build();
action.perform();
System.out.println("Slider moved");
}
}
Run Code Online (Sandbox Code Playgroud)
小智 5
我总是使用此代码来移动滑动条:
action.click(webElement).build().perform();
Thread.sleep(1000);
for (int i = 0; i < 10; i++) {
action.sendKeys(Keys.ARROW_LEFT).build().perform();
Thread.sleep(200);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
24941 次 |
| 最近记录: |