OS: Windows 7
Selenium Version:
c#, selenium3.9.1
Browser:
chrome 63
I need move 10 each, but real first time move 10, second move 20 , third move 30, the real move value increment 10 each;
the code is following:
` int y = 1;
int currentlocal = ele.Location.X+ele.Size.Width;
int nextlocal = 0;
int movewith = 10;
for (int i = 1; i < width; i++)
{
currentlocal = currentlocal + movewith * i;
nextlocal = currentlocal + movewith * (i + 1);
Console.WriteLine(i + ";current ele local:" + currentlocal + ": next ele local:" + nextlocal);
action.MoveByOffset(movewith, y).Perform();
Console.WriteLine("ele real local:" + (ele.Location.X + ele.Size.Width));
Thread.Sleep(waittime);
}`
This is by design. Actions are cumulative unless you reset them. The right approach would be something like this:
Actions action = new Actions(driver);
action.MoveByOffset(10, 1);
for (int i = 1; i < width; i++)
{
action.Perform();
}
Though the above example is oversimplified, the idea still holds.
thanks for reply
if i need move different distance , eg first 20 , second 10, third 30 ,how i can do ?
Easiest way is to clear or reset the Action object, or create a new one for each move. That class is lightweight specifically so it can be created over and over again.
Thank you very much ,you help me a lot .
i use this method drag and drop the slide block, but it return failed.
I use python and meet the same problem.I used to try to reset the action,but the 'click_and_hold' ac
Duplicate of #tion will also be cleared.Create a new action, what a good idea.Thank you very much.My question now is why the action is designed like this?
Most helpful comment
Easiest way is to clear or reset the
Actionobject, or create a new one for each move. That class is lightweight specifically so it can be created over and over again.