Vladimir Potapov
Vladimir Potapov

Reputation: 2437

Selenium WebDriver Second click not working

I am preforming making clicks by position, When I move to position and make click. The first click working fine, but the other there is no reaction.

My main goal: I have list with (x,y) were I need to click

Code

 Actions action = new Actions(driver);
 action.MoveByOffset(BlocX + 12, BlocY + 12);
 action.Click();//only this is working
 action.Perform();
 action.Release();

 action.MoveByOffset(BlocX + 36, BlocY + 12);
 action.Click();
 action.Perform();
 action.Release();

 action.MoveByOffset(BlocX + 60, BlocY + 12);
 action.Click();
 action.Perform();
 action.Release();

What am I missing in this code, how do I preform all the clicks?

I tried to make perform in the end this is not working too

This is code

  Actions action = new Actions(driver); 
  action.MoveByOffset(BlocX + 12, BlocY + 12);
  action.Click();
  action.Release();
  action.MoveByOffset(BlocX + 36, BlocY + 12);
  action.Click();
  action.Release();
  action.MoveByOffset(BlocX + 60, BlocY + 12);
  action.Click();

  action.Perform();

This make more that one click only in this case when i don't move mouse position again

  Actions builder = new Actions(driver);
  builder.MoveByOffset(BlocX + 12, BlocY + 12).Click();
  builder.Click();
  builder.Click();
  builder.Click();
  builder.Perform();

Any one have idea how to do all clicks on all positions?

Upvotes: 2

Views: 632

Answers (1)

StrikerVillain
StrikerVillain

Reputation: 3776

Try building all the sequential actions and then performing it. Also call new on Actions class every time you have to click because, according to your code while performing the second click, the mouse pointer would be at position BlocX + 12. So your second click is happening at BlockX + 12 + BlockX + 36.

// click 1
Actions actions = new Actions(driver);
actions.moveByOffset(BlocX + 12, BlocY + 12).click().build().perform();

// click 2
actions = new Actions(driver);
actions.moveByOffset(BlocX + 36, BlocY + 12).click().build().perform();

// click 3
actions = new Actions(driver);
actions.moveByOffset(BlocX + 60, BlocY + 12).click().build().perform();

Upvotes: 1

Related Questions