Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

when use MoveByOffset repeatedly ,the real offsetX value auto increase #5747

Closed
duoduoxi opened this issue Apr 10, 2018 · 5 comments
Closed

Comments

@duoduoxi
Copy link

Meta -

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);
          }`
@jimevans
Copy link
Member

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.

@duoduoxi
Copy link
Author

thanks for reply
if i need move different distance , eg first 20 , second 10, third 30 ,how i can do ?

@jimevans
Copy link
Member

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.

@duoduoxi
Copy link
Author

Thank you very much ,you help me a lot .

i use this method drag and drop the slide block, but it return failed.

@vansl
Copy link

vansl commented Jun 6, 2018

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?

@lock lock bot locked and limited conversation to collaborators Aug 15, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants