I have to test a case where using an option given on toolbar I can add sticky note to the image. I am able to perform this but the stickynote disappears after click command in selenium code get executed.

driver.findElement(By.xpath("//*[@id=\"ci-tool-top\"]/div/div[5]/div[2]/div/div/div[1]/button[5]")).click(); // Command to select note from toolbar

Actions builder = new Actions(driver);  
builder.moveByOffset(528, 421).clickAndHold().build().perform(); //Command to click on image so that note sticks on it
  • From your steps, it looks like you're intentions are 1. Clicking and releasing the note on the toolbar 2. Moving mouse to the image (note: with how you have it built there is a good chance you're not actually moving the mouse to the image) 3. Clicking and holding the mouse. Are you sure you don't want to do these steps instead? 1. Click and hold the note on the toolbar 2. drag mouse to image 3. release mouse click
    – mrfreester
    Jul 31 '17 at 14:56
  • Steps are 1. Clicking the note on toolbar 2. Moving mouse to image 3. Clicking the mouse on image. The purpose i used click and hold here is a trial to get solution for my problem which is when I click on image (The final step) note appears but then disappear as testcase finishes
    – Rabia Asif
    Aug 1 '17 at 5:43
  • You may have already tried this, but it might be worth trying to put the whole thing in an actions. Something like builder.click(toolbarNoteElement).moveToElement(imageElement).click().perform(); Can you provide some html for the image? It's probably worth figuring out a selector for that, which I could help with and that might help solve this issue.
    – mrfreester
    Aug 1 '17 at 15:23
  • FWIW, my best theory right now is that when you move and click, it's not actually interacting with the image which is why the note appears, and then disappears (because it doesn't think you actually clicked on the image... even though it probably should...)
    – mrfreester
    Aug 1 '17 at 15:25
  • @mrfreester So your solution worked (Y) Can you please post it as an answer so that I can accept it
    – Rabia Asif
    Aug 2 '17 at 5:09

This appears to be an issue with the driver losing track of the click on the note as soon as the click on the image occurs. This is pretty common with some types of dropdowns, but applies in other situations as well.

The solution is to wrap the entire set of actions as Actions:

// note from toolbar element
WebElement toolbarNoteElement = driver.findElement(
WebElement imageElement = driver.findElement(/*<Some By for the image>*/);

Actions builder = new Actions(driver);  
//Command to click on image so that note sticks on it

You can probably replace the moveToElement(imageElement) with your moveByOffset assuming that actually ends up on the image, but if you can find a selector for the image that will probably end up being more stable. Cheers :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.