如何用C#调整Selenium中MoveByOffset的速度?

disbfnqx  于 2023-01-05  发布在  C#
关注(0)|答案(1)|浏览(258)

我的代码是:

By slider_humidity = By.XPath("ExampleXpath");
var hSlider = driver.FindElement(slider_humidity);
Actions action = new Actions(driver);
action.MoveToElement(hSlider, 0, 0); //this will make it to start at 0,0 of the slider
action.ClickAndHold(); //don't pass the element, now it will click current mouse location which is (0,0)
action.MoveByOffset(pixelstomove, 0); // move by 30 pixel from 0
action.Build().Perform();

它似乎是太快了,我的目标网站,我需要改变它的速度。它基本上是从0点到给定点瞬间。但我希望它滑动滑块缓慢。也替代方式使用C#中的Javascript将不胜感激,只要我可以调整速度,我的愿望。

jdgnovmf

jdgnovmf1#

试试这个:

By slider_humidity = By.XPath("ExampleXpath");
var hSlider = driver.FindElement(slider_humidity);
PointerInputDevice mouse = new PointerInputDevice();
Actions action = new Actions(driver);
action.MoveToElement(hSlider, 0, 0) //this will make it to start at 0,0 of the slider
      .ClickAndHold() //don't pass the element, now it will click current mouse location which is (0,0)
      .tick(mouse.CreatePointerMove(hSlider, pixelstomove, 0, TimeSpan.FromMilliseconds(200))) // Move by <pixelstomove> in x-offset
      .Build()
      .Perform();

相关问题