Double click action not working whereas single click works on an element in selenium





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















I am trying to double click on an element but unable to perform the action. Single click works fine on the same element. Am i missing something?. Can someone please help me out with this.



HTML of the element:



<tbody><tr class="mclS" tabindex="0"> <td><div class="mclC" style="height:14px;">&nbsp;&nbsp;*&nbsp;Quarter&nbsp;to&nbsp;Date</div></td> </tr> </tbody>


I have tried various ways of double clicking the element:



WebElement date = driver.findElement(By.cssSelector(".mlstBody>tbody>tr:nth-child(8)"));

=> actions.doubleClick(date).build().perform();

=> actions.doubleClick(date);

=> ((JavascriptExecutor)driver).executeScript("var evt = document.createEvent('MouseEvents');" + "evt.initMouseEvent('dblclick',true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0,null);" + "arguments[0].dispatchEvent(evt);",date);

=> actions.moveToElement(date).doubleClick().build();
actions.perform();









share|improve this question

























  • @Brian I tried this approach aswell but still don't work.

    – Ayisha
    Nov 26 '18 at 18:17











  • What are you attempting to double click on?

    – Brian
    Nov 26 '18 at 18:51











  • i am trying to double click on a element in the list, when i perform double click action it will just scroll through the list where the element is present but does not double click on that element. Single click works perfectly fine if i use date.click().. If i use actions.click(date).perform() it does not click on that element.

    – Ayisha
    Nov 27 '18 at 3:58













  • @Ayisha Update the question with the relevant HTML and the information on which Selenium Language Binding Art are you using? Java / Python / C# / NodeJS ?

    – DebanjanB
    Nov 27 '18 at 8:27













  • @DebanjanB i am using Java and i have updated the HTML

    – Ayisha
    Nov 27 '18 at 9:35


















1















I am trying to double click on an element but unable to perform the action. Single click works fine on the same element. Am i missing something?. Can someone please help me out with this.



HTML of the element:



<tbody><tr class="mclS" tabindex="0"> <td><div class="mclC" style="height:14px;">&nbsp;&nbsp;*&nbsp;Quarter&nbsp;to&nbsp;Date</div></td> </tr> </tbody>


I have tried various ways of double clicking the element:



WebElement date = driver.findElement(By.cssSelector(".mlstBody>tbody>tr:nth-child(8)"));

=> actions.doubleClick(date).build().perform();

=> actions.doubleClick(date);

=> ((JavascriptExecutor)driver).executeScript("var evt = document.createEvent('MouseEvents');" + "evt.initMouseEvent('dblclick',true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0,null);" + "arguments[0].dispatchEvent(evt);",date);

=> actions.moveToElement(date).doubleClick().build();
actions.perform();









share|improve this question

























  • @Brian I tried this approach aswell but still don't work.

    – Ayisha
    Nov 26 '18 at 18:17











  • What are you attempting to double click on?

    – Brian
    Nov 26 '18 at 18:51











  • i am trying to double click on a element in the list, when i perform double click action it will just scroll through the list where the element is present but does not double click on that element. Single click works perfectly fine if i use date.click().. If i use actions.click(date).perform() it does not click on that element.

    – Ayisha
    Nov 27 '18 at 3:58













  • @Ayisha Update the question with the relevant HTML and the information on which Selenium Language Binding Art are you using? Java / Python / C# / NodeJS ?

    – DebanjanB
    Nov 27 '18 at 8:27













  • @DebanjanB i am using Java and i have updated the HTML

    – Ayisha
    Nov 27 '18 at 9:35














1












1








1








I am trying to double click on an element but unable to perform the action. Single click works fine on the same element. Am i missing something?. Can someone please help me out with this.



HTML of the element:



<tbody><tr class="mclS" tabindex="0"> <td><div class="mclC" style="height:14px;">&nbsp;&nbsp;*&nbsp;Quarter&nbsp;to&nbsp;Date</div></td> </tr> </tbody>


I have tried various ways of double clicking the element:



WebElement date = driver.findElement(By.cssSelector(".mlstBody>tbody>tr:nth-child(8)"));

=> actions.doubleClick(date).build().perform();

=> actions.doubleClick(date);

=> ((JavascriptExecutor)driver).executeScript("var evt = document.createEvent('MouseEvents');" + "evt.initMouseEvent('dblclick',true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0,null);" + "arguments[0].dispatchEvent(evt);",date);

=> actions.moveToElement(date).doubleClick().build();
actions.perform();









share|improve this question
















I am trying to double click on an element but unable to perform the action. Single click works fine on the same element. Am i missing something?. Can someone please help me out with this.



HTML of the element:



<tbody><tr class="mclS" tabindex="0"> <td><div class="mclC" style="height:14px;">&nbsp;&nbsp;*&nbsp;Quarter&nbsp;to&nbsp;Date</div></td> </tr> </tbody>


I have tried various ways of double clicking the element:



WebElement date = driver.findElement(By.cssSelector(".mlstBody>tbody>tr:nth-child(8)"));

=> actions.doubleClick(date).build().perform();

=> actions.doubleClick(date);

=> ((JavascriptExecutor)driver).executeScript("var evt = document.createEvent('MouseEvents');" + "evt.initMouseEvent('dblclick',true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0,null);" + "arguments[0].dispatchEvent(evt);",date);

=> actions.moveToElement(date).doubleClick().build();
actions.perform();






java selenium xpath css-selectors double-click






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 27 '18 at 10:26









DebanjanB

46.8k134790




46.8k134790










asked Nov 26 '18 at 16:59









AyishaAyisha

63




63













  • @Brian I tried this approach aswell but still don't work.

    – Ayisha
    Nov 26 '18 at 18:17











  • What are you attempting to double click on?

    – Brian
    Nov 26 '18 at 18:51











  • i am trying to double click on a element in the list, when i perform double click action it will just scroll through the list where the element is present but does not double click on that element. Single click works perfectly fine if i use date.click().. If i use actions.click(date).perform() it does not click on that element.

    – Ayisha
    Nov 27 '18 at 3:58













  • @Ayisha Update the question with the relevant HTML and the information on which Selenium Language Binding Art are you using? Java / Python / C# / NodeJS ?

    – DebanjanB
    Nov 27 '18 at 8:27













  • @DebanjanB i am using Java and i have updated the HTML

    – Ayisha
    Nov 27 '18 at 9:35



















  • @Brian I tried this approach aswell but still don't work.

    – Ayisha
    Nov 26 '18 at 18:17











  • What are you attempting to double click on?

    – Brian
    Nov 26 '18 at 18:51











  • i am trying to double click on a element in the list, when i perform double click action it will just scroll through the list where the element is present but does not double click on that element. Single click works perfectly fine if i use date.click().. If i use actions.click(date).perform() it does not click on that element.

    – Ayisha
    Nov 27 '18 at 3:58













  • @Ayisha Update the question with the relevant HTML and the information on which Selenium Language Binding Art are you using? Java / Python / C# / NodeJS ?

    – DebanjanB
    Nov 27 '18 at 8:27













  • @DebanjanB i am using Java and i have updated the HTML

    – Ayisha
    Nov 27 '18 at 9:35

















@Brian I tried this approach aswell but still don't work.

– Ayisha
Nov 26 '18 at 18:17





@Brian I tried this approach aswell but still don't work.

– Ayisha
Nov 26 '18 at 18:17













What are you attempting to double click on?

– Brian
Nov 26 '18 at 18:51





What are you attempting to double click on?

– Brian
Nov 26 '18 at 18:51













i am trying to double click on a element in the list, when i perform double click action it will just scroll through the list where the element is present but does not double click on that element. Single click works perfectly fine if i use date.click().. If i use actions.click(date).perform() it does not click on that element.

– Ayisha
Nov 27 '18 at 3:58







i am trying to double click on a element in the list, when i perform double click action it will just scroll through the list where the element is present but does not double click on that element. Single click works perfectly fine if i use date.click().. If i use actions.click(date).perform() it does not click on that element.

– Ayisha
Nov 27 '18 at 3:58















@Ayisha Update the question with the relevant HTML and the information on which Selenium Language Binding Art are you using? Java / Python / C# / NodeJS ?

– DebanjanB
Nov 27 '18 at 8:27







@Ayisha Update the question with the relevant HTML and the information on which Selenium Language Binding Art are you using? Java / Python / C# / NodeJS ?

– DebanjanB
Nov 27 '18 at 8:27















@DebanjanB i am using Java and i have updated the HTML

– Ayisha
Nov 27 '18 at 9:35





@DebanjanB i am using Java and i have updated the HTML

– Ayisha
Nov 27 '18 at 9:35












3 Answers
3






active

oldest

votes


















0














For reference.



You need to perform the action on the element like this:



Actions action = new Actions(driver);
WebElement date = driver.findElement(By.cssSelector(".mlstBody>tbody>tr:nth-child(8)"));
action.doubleClick(date).perform();


NOTE: This example uses Java.



Additional NOTE: For Selenium 3.5 and up, you will need to do the following:



action.moveToElement(driver.findElement(By.cssSelector(".msltBody>tbody>tr:nth-child(8)")).doubleClick().build().perform();





share|improve this answer


























  • Tried even that but nothing seems to work. Is there any other way to double click?

    – Ayisha
    Nov 26 '18 at 18:41



















0














I'm going to guess you are using Firefox? I think there is an issue written up with doubleclick and the geckodriver. I don't think it's fixed yet. I see you tried one way in JavaScript. Can you try this way though? It worked for me in Firefox.



document.querySelector(".mlstBody>tbody>tr:nth-child(8)").dispatchEvent(new MouseEvent("dblclick"));





share|improve this answer
























  • I am using chrome to automate and i tried with your suggestion but still does not double click.

    – Ayisha
    Nov 28 '18 at 9:19











  • You say when you doubleclick the element, the value populates a textbox. Why are we not getting the full HTML then? The html you have given us has no textbox shown. If we are to properly help you, then you need to give us everything we can to do so. Right now we are just shooting in the dark and giving guesses.

    – IamBatman
    Nov 28 '18 at 15:32



















0














Seems you were pretty close. To invoke doubleClick() through Actions class you can use either of the following solutions:





  • Using cssSelector:



    WebElement date = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("tr.mclS>td>div.mclC")));
    new Actions(driver).moveToElement(date).doubleClick().build().perform();



  • Using xpath:



    WebElement date = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//tr[@class='mclS']/td/div[@class='mclC' and contains(.,'Date')]")));
    new Actions(driver).moveToElement(date).doubleClick().build().perform();





Update



As you are still unable to invoke doubleClick() on the desired element as an alternative to make Mouse Double Click you can write a script and pass it to the executeScript() method as follows:





  • Script :



    String jsDoubleClick = 
    "var target = arguments[0]; " +
    "var offsetX = arguments[1]; " +
    "var offsetY = arguments[2]; " +
    "var rect = target.getBoundingClientRect(); " +
    "var cx = rect.left + (offsetX || (rect.width / 2)); " +
    "var cy = rect.top + (offsetY || (rect.height / 2)); " +
    " " +
    "emit('mousedown', {clientX: cx, clientY: cy, buttons: 1}); " +
    "emit('mouseup', {clientX: cx, clientY: cy}); " +
    "emit('mousedown', {clientX: cx, clientY: cy, buttons: 1}); " +
    "emit('mouseup', {clientX: cx, clientY: cy}); " +
    "emit('click', {clientX: cx, clientY: cy, detail: 2}); " +
    " " +
    "function emit(name, init) { " +
    "target.dispatchEvent(new MouseEvent(name, init)); " +
    "} " ;



  • Invoking the script through executeScript() from your @Test :



    new Actions(driver).moveToElement(myElem, posX, posY).perform();
    ((JavascriptExecutor)driver).executeScript(jsDoubleClick, myElem, posX, posY);







share|improve this answer


























  • Tried both the ways you suggested but still doesn't work. Please let me know if there is approach.

    – Ayisha
    Nov 27 '18 at 10:57











  • @Ayisha Your comment doesn't helps me either. Sorry, the answer didn't help you to solve your problem but how am I going to improve my post with that feedback?

    – DebanjanB
    Nov 27 '18 at 10:59













  • sry there was a typo error in my previous comment. I wanted to know if there is anyother way of achieving the double click on the element.

    – Ayisha
    Nov 27 '18 at 11:12











  • @Ayisha Can you update the question with some more information, why do you need to doubleClick() instead of a click()

    – DebanjanB
    Nov 27 '18 at 11:15











  • when I double click the element the value gets populated in the text box.

    – Ayisha
    Nov 27 '18 at 11:23












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53485797%2fdouble-click-action-not-working-whereas-single-click-works-on-an-element-in-sele%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























3 Answers
3






active

oldest

votes








3 Answers
3






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














For reference.



You need to perform the action on the element like this:



Actions action = new Actions(driver);
WebElement date = driver.findElement(By.cssSelector(".mlstBody>tbody>tr:nth-child(8)"));
action.doubleClick(date).perform();


NOTE: This example uses Java.



Additional NOTE: For Selenium 3.5 and up, you will need to do the following:



action.moveToElement(driver.findElement(By.cssSelector(".msltBody>tbody>tr:nth-child(8)")).doubleClick().build().perform();





share|improve this answer


























  • Tried even that but nothing seems to work. Is there any other way to double click?

    – Ayisha
    Nov 26 '18 at 18:41
















0














For reference.



You need to perform the action on the element like this:



Actions action = new Actions(driver);
WebElement date = driver.findElement(By.cssSelector(".mlstBody>tbody>tr:nth-child(8)"));
action.doubleClick(date).perform();


NOTE: This example uses Java.



Additional NOTE: For Selenium 3.5 and up, you will need to do the following:



action.moveToElement(driver.findElement(By.cssSelector(".msltBody>tbody>tr:nth-child(8)")).doubleClick().build().perform();





share|improve this answer


























  • Tried even that but nothing seems to work. Is there any other way to double click?

    – Ayisha
    Nov 26 '18 at 18:41














0












0








0







For reference.



You need to perform the action on the element like this:



Actions action = new Actions(driver);
WebElement date = driver.findElement(By.cssSelector(".mlstBody>tbody>tr:nth-child(8)"));
action.doubleClick(date).perform();


NOTE: This example uses Java.



Additional NOTE: For Selenium 3.5 and up, you will need to do the following:



action.moveToElement(driver.findElement(By.cssSelector(".msltBody>tbody>tr:nth-child(8)")).doubleClick().build().perform();





share|improve this answer















For reference.



You need to perform the action on the element like this:



Actions action = new Actions(driver);
WebElement date = driver.findElement(By.cssSelector(".mlstBody>tbody>tr:nth-child(8)"));
action.doubleClick(date).perform();


NOTE: This example uses Java.



Additional NOTE: For Selenium 3.5 and up, you will need to do the following:



action.moveToElement(driver.findElement(By.cssSelector(".msltBody>tbody>tr:nth-child(8)")).doubleClick().build().perform();






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 26 '18 at 18:09

























answered Nov 26 '18 at 18:02









BrianBrian

4,65972943




4,65972943













  • Tried even that but nothing seems to work. Is there any other way to double click?

    – Ayisha
    Nov 26 '18 at 18:41



















  • Tried even that but nothing seems to work. Is there any other way to double click?

    – Ayisha
    Nov 26 '18 at 18:41

















Tried even that but nothing seems to work. Is there any other way to double click?

– Ayisha
Nov 26 '18 at 18:41





Tried even that but nothing seems to work. Is there any other way to double click?

– Ayisha
Nov 26 '18 at 18:41













0














I'm going to guess you are using Firefox? I think there is an issue written up with doubleclick and the geckodriver. I don't think it's fixed yet. I see you tried one way in JavaScript. Can you try this way though? It worked for me in Firefox.



document.querySelector(".mlstBody>tbody>tr:nth-child(8)").dispatchEvent(new MouseEvent("dblclick"));





share|improve this answer
























  • I am using chrome to automate and i tried with your suggestion but still does not double click.

    – Ayisha
    Nov 28 '18 at 9:19











  • You say when you doubleclick the element, the value populates a textbox. Why are we not getting the full HTML then? The html you have given us has no textbox shown. If we are to properly help you, then you need to give us everything we can to do so. Right now we are just shooting in the dark and giving guesses.

    – IamBatman
    Nov 28 '18 at 15:32
















0














I'm going to guess you are using Firefox? I think there is an issue written up with doubleclick and the geckodriver. I don't think it's fixed yet. I see you tried one way in JavaScript. Can you try this way though? It worked for me in Firefox.



document.querySelector(".mlstBody>tbody>tr:nth-child(8)").dispatchEvent(new MouseEvent("dblclick"));





share|improve this answer
























  • I am using chrome to automate and i tried with your suggestion but still does not double click.

    – Ayisha
    Nov 28 '18 at 9:19











  • You say when you doubleclick the element, the value populates a textbox. Why are we not getting the full HTML then? The html you have given us has no textbox shown. If we are to properly help you, then you need to give us everything we can to do so. Right now we are just shooting in the dark and giving guesses.

    – IamBatman
    Nov 28 '18 at 15:32














0












0








0







I'm going to guess you are using Firefox? I think there is an issue written up with doubleclick and the geckodriver. I don't think it's fixed yet. I see you tried one way in JavaScript. Can you try this way though? It worked for me in Firefox.



document.querySelector(".mlstBody>tbody>tr:nth-child(8)").dispatchEvent(new MouseEvent("dblclick"));





share|improve this answer













I'm going to guess you are using Firefox? I think there is an issue written up with doubleclick and the geckodriver. I don't think it's fixed yet. I see you tried one way in JavaScript. Can you try this way though? It worked for me in Firefox.



document.querySelector(".mlstBody>tbody>tr:nth-child(8)").dispatchEvent(new MouseEvent("dblclick"));






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 27 '18 at 18:22









IamBatmanIamBatman

7461018




7461018













  • I am using chrome to automate and i tried with your suggestion but still does not double click.

    – Ayisha
    Nov 28 '18 at 9:19











  • You say when you doubleclick the element, the value populates a textbox. Why are we not getting the full HTML then? The html you have given us has no textbox shown. If we are to properly help you, then you need to give us everything we can to do so. Right now we are just shooting in the dark and giving guesses.

    – IamBatman
    Nov 28 '18 at 15:32



















  • I am using chrome to automate and i tried with your suggestion but still does not double click.

    – Ayisha
    Nov 28 '18 at 9:19











  • You say when you doubleclick the element, the value populates a textbox. Why are we not getting the full HTML then? The html you have given us has no textbox shown. If we are to properly help you, then you need to give us everything we can to do so. Right now we are just shooting in the dark and giving guesses.

    – IamBatman
    Nov 28 '18 at 15:32

















I am using chrome to automate and i tried with your suggestion but still does not double click.

– Ayisha
Nov 28 '18 at 9:19





I am using chrome to automate and i tried with your suggestion but still does not double click.

– Ayisha
Nov 28 '18 at 9:19













You say when you doubleclick the element, the value populates a textbox. Why are we not getting the full HTML then? The html you have given us has no textbox shown. If we are to properly help you, then you need to give us everything we can to do so. Right now we are just shooting in the dark and giving guesses.

– IamBatman
Nov 28 '18 at 15:32





You say when you doubleclick the element, the value populates a textbox. Why are we not getting the full HTML then? The html you have given us has no textbox shown. If we are to properly help you, then you need to give us everything we can to do so. Right now we are just shooting in the dark and giving guesses.

– IamBatman
Nov 28 '18 at 15:32











0














Seems you were pretty close. To invoke doubleClick() through Actions class you can use either of the following solutions:





  • Using cssSelector:



    WebElement date = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("tr.mclS>td>div.mclC")));
    new Actions(driver).moveToElement(date).doubleClick().build().perform();



  • Using xpath:



    WebElement date = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//tr[@class='mclS']/td/div[@class='mclC' and contains(.,'Date')]")));
    new Actions(driver).moveToElement(date).doubleClick().build().perform();





Update



As you are still unable to invoke doubleClick() on the desired element as an alternative to make Mouse Double Click you can write a script and pass it to the executeScript() method as follows:





  • Script :



    String jsDoubleClick = 
    "var target = arguments[0]; " +
    "var offsetX = arguments[1]; " +
    "var offsetY = arguments[2]; " +
    "var rect = target.getBoundingClientRect(); " +
    "var cx = rect.left + (offsetX || (rect.width / 2)); " +
    "var cy = rect.top + (offsetY || (rect.height / 2)); " +
    " " +
    "emit('mousedown', {clientX: cx, clientY: cy, buttons: 1}); " +
    "emit('mouseup', {clientX: cx, clientY: cy}); " +
    "emit('mousedown', {clientX: cx, clientY: cy, buttons: 1}); " +
    "emit('mouseup', {clientX: cx, clientY: cy}); " +
    "emit('click', {clientX: cx, clientY: cy, detail: 2}); " +
    " " +
    "function emit(name, init) { " +
    "target.dispatchEvent(new MouseEvent(name, init)); " +
    "} " ;



  • Invoking the script through executeScript() from your @Test :



    new Actions(driver).moveToElement(myElem, posX, posY).perform();
    ((JavascriptExecutor)driver).executeScript(jsDoubleClick, myElem, posX, posY);







share|improve this answer


























  • Tried both the ways you suggested but still doesn't work. Please let me know if there is approach.

    – Ayisha
    Nov 27 '18 at 10:57











  • @Ayisha Your comment doesn't helps me either. Sorry, the answer didn't help you to solve your problem but how am I going to improve my post with that feedback?

    – DebanjanB
    Nov 27 '18 at 10:59













  • sry there was a typo error in my previous comment. I wanted to know if there is anyother way of achieving the double click on the element.

    – Ayisha
    Nov 27 '18 at 11:12











  • @Ayisha Can you update the question with some more information, why do you need to doubleClick() instead of a click()

    – DebanjanB
    Nov 27 '18 at 11:15











  • when I double click the element the value gets populated in the text box.

    – Ayisha
    Nov 27 '18 at 11:23
















0














Seems you were pretty close. To invoke doubleClick() through Actions class you can use either of the following solutions:





  • Using cssSelector:



    WebElement date = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("tr.mclS>td>div.mclC")));
    new Actions(driver).moveToElement(date).doubleClick().build().perform();



  • Using xpath:



    WebElement date = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//tr[@class='mclS']/td/div[@class='mclC' and contains(.,'Date')]")));
    new Actions(driver).moveToElement(date).doubleClick().build().perform();





Update



As you are still unable to invoke doubleClick() on the desired element as an alternative to make Mouse Double Click you can write a script and pass it to the executeScript() method as follows:





  • Script :



    String jsDoubleClick = 
    "var target = arguments[0]; " +
    "var offsetX = arguments[1]; " +
    "var offsetY = arguments[2]; " +
    "var rect = target.getBoundingClientRect(); " +
    "var cx = rect.left + (offsetX || (rect.width / 2)); " +
    "var cy = rect.top + (offsetY || (rect.height / 2)); " +
    " " +
    "emit('mousedown', {clientX: cx, clientY: cy, buttons: 1}); " +
    "emit('mouseup', {clientX: cx, clientY: cy}); " +
    "emit('mousedown', {clientX: cx, clientY: cy, buttons: 1}); " +
    "emit('mouseup', {clientX: cx, clientY: cy}); " +
    "emit('click', {clientX: cx, clientY: cy, detail: 2}); " +
    " " +
    "function emit(name, init) { " +
    "target.dispatchEvent(new MouseEvent(name, init)); " +
    "} " ;



  • Invoking the script through executeScript() from your @Test :



    new Actions(driver).moveToElement(myElem, posX, posY).perform();
    ((JavascriptExecutor)driver).executeScript(jsDoubleClick, myElem, posX, posY);







share|improve this answer


























  • Tried both the ways you suggested but still doesn't work. Please let me know if there is approach.

    – Ayisha
    Nov 27 '18 at 10:57











  • @Ayisha Your comment doesn't helps me either. Sorry, the answer didn't help you to solve your problem but how am I going to improve my post with that feedback?

    – DebanjanB
    Nov 27 '18 at 10:59













  • sry there was a typo error in my previous comment. I wanted to know if there is anyother way of achieving the double click on the element.

    – Ayisha
    Nov 27 '18 at 11:12











  • @Ayisha Can you update the question with some more information, why do you need to doubleClick() instead of a click()

    – DebanjanB
    Nov 27 '18 at 11:15











  • when I double click the element the value gets populated in the text box.

    – Ayisha
    Nov 27 '18 at 11:23














0












0








0







Seems you were pretty close. To invoke doubleClick() through Actions class you can use either of the following solutions:





  • Using cssSelector:



    WebElement date = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("tr.mclS>td>div.mclC")));
    new Actions(driver).moveToElement(date).doubleClick().build().perform();



  • Using xpath:



    WebElement date = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//tr[@class='mclS']/td/div[@class='mclC' and contains(.,'Date')]")));
    new Actions(driver).moveToElement(date).doubleClick().build().perform();





Update



As you are still unable to invoke doubleClick() on the desired element as an alternative to make Mouse Double Click you can write a script and pass it to the executeScript() method as follows:





  • Script :



    String jsDoubleClick = 
    "var target = arguments[0]; " +
    "var offsetX = arguments[1]; " +
    "var offsetY = arguments[2]; " +
    "var rect = target.getBoundingClientRect(); " +
    "var cx = rect.left + (offsetX || (rect.width / 2)); " +
    "var cy = rect.top + (offsetY || (rect.height / 2)); " +
    " " +
    "emit('mousedown', {clientX: cx, clientY: cy, buttons: 1}); " +
    "emit('mouseup', {clientX: cx, clientY: cy}); " +
    "emit('mousedown', {clientX: cx, clientY: cy, buttons: 1}); " +
    "emit('mouseup', {clientX: cx, clientY: cy}); " +
    "emit('click', {clientX: cx, clientY: cy, detail: 2}); " +
    " " +
    "function emit(name, init) { " +
    "target.dispatchEvent(new MouseEvent(name, init)); " +
    "} " ;



  • Invoking the script through executeScript() from your @Test :



    new Actions(driver).moveToElement(myElem, posX, posY).perform();
    ((JavascriptExecutor)driver).executeScript(jsDoubleClick, myElem, posX, posY);







share|improve this answer















Seems you were pretty close. To invoke doubleClick() through Actions class you can use either of the following solutions:





  • Using cssSelector:



    WebElement date = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("tr.mclS>td>div.mclC")));
    new Actions(driver).moveToElement(date).doubleClick().build().perform();



  • Using xpath:



    WebElement date = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//tr[@class='mclS']/td/div[@class='mclC' and contains(.,'Date')]")));
    new Actions(driver).moveToElement(date).doubleClick().build().perform();





Update



As you are still unable to invoke doubleClick() on the desired element as an alternative to make Mouse Double Click you can write a script and pass it to the executeScript() method as follows:





  • Script :



    String jsDoubleClick = 
    "var target = arguments[0]; " +
    "var offsetX = arguments[1]; " +
    "var offsetY = arguments[2]; " +
    "var rect = target.getBoundingClientRect(); " +
    "var cx = rect.left + (offsetX || (rect.width / 2)); " +
    "var cy = rect.top + (offsetY || (rect.height / 2)); " +
    " " +
    "emit('mousedown', {clientX: cx, clientY: cy, buttons: 1}); " +
    "emit('mouseup', {clientX: cx, clientY: cy}); " +
    "emit('mousedown', {clientX: cx, clientY: cy, buttons: 1}); " +
    "emit('mouseup', {clientX: cx, clientY: cy}); " +
    "emit('click', {clientX: cx, clientY: cy, detail: 2}); " +
    " " +
    "function emit(name, init) { " +
    "target.dispatchEvent(new MouseEvent(name, init)); " +
    "} " ;



  • Invoking the script through executeScript() from your @Test :



    new Actions(driver).moveToElement(myElem, posX, posY).perform();
    ((JavascriptExecutor)driver).executeScript(jsDoubleClick, myElem, posX, posY);








share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 28 '18 at 6:43

























answered Nov 27 '18 at 10:28









DebanjanBDebanjanB

46.8k134790




46.8k134790













  • Tried both the ways you suggested but still doesn't work. Please let me know if there is approach.

    – Ayisha
    Nov 27 '18 at 10:57











  • @Ayisha Your comment doesn't helps me either. Sorry, the answer didn't help you to solve your problem but how am I going to improve my post with that feedback?

    – DebanjanB
    Nov 27 '18 at 10:59













  • sry there was a typo error in my previous comment. I wanted to know if there is anyother way of achieving the double click on the element.

    – Ayisha
    Nov 27 '18 at 11:12











  • @Ayisha Can you update the question with some more information, why do you need to doubleClick() instead of a click()

    – DebanjanB
    Nov 27 '18 at 11:15











  • when I double click the element the value gets populated in the text box.

    – Ayisha
    Nov 27 '18 at 11:23



















  • Tried both the ways you suggested but still doesn't work. Please let me know if there is approach.

    – Ayisha
    Nov 27 '18 at 10:57











  • @Ayisha Your comment doesn't helps me either. Sorry, the answer didn't help you to solve your problem but how am I going to improve my post with that feedback?

    – DebanjanB
    Nov 27 '18 at 10:59













  • sry there was a typo error in my previous comment. I wanted to know if there is anyother way of achieving the double click on the element.

    – Ayisha
    Nov 27 '18 at 11:12











  • @Ayisha Can you update the question with some more information, why do you need to doubleClick() instead of a click()

    – DebanjanB
    Nov 27 '18 at 11:15











  • when I double click the element the value gets populated in the text box.

    – Ayisha
    Nov 27 '18 at 11:23

















Tried both the ways you suggested but still doesn't work. Please let me know if there is approach.

– Ayisha
Nov 27 '18 at 10:57





Tried both the ways you suggested but still doesn't work. Please let me know if there is approach.

– Ayisha
Nov 27 '18 at 10:57













@Ayisha Your comment doesn't helps me either. Sorry, the answer didn't help you to solve your problem but how am I going to improve my post with that feedback?

– DebanjanB
Nov 27 '18 at 10:59







@Ayisha Your comment doesn't helps me either. Sorry, the answer didn't help you to solve your problem but how am I going to improve my post with that feedback?

– DebanjanB
Nov 27 '18 at 10:59















sry there was a typo error in my previous comment. I wanted to know if there is anyother way of achieving the double click on the element.

– Ayisha
Nov 27 '18 at 11:12





sry there was a typo error in my previous comment. I wanted to know if there is anyother way of achieving the double click on the element.

– Ayisha
Nov 27 '18 at 11:12













@Ayisha Can you update the question with some more information, why do you need to doubleClick() instead of a click()

– DebanjanB
Nov 27 '18 at 11:15





@Ayisha Can you update the question with some more information, why do you need to doubleClick() instead of a click()

– DebanjanB
Nov 27 '18 at 11:15













when I double click the element the value gets populated in the text box.

– Ayisha
Nov 27 '18 at 11:23





when I double click the element the value gets populated in the text box.

– Ayisha
Nov 27 '18 at 11:23


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53485797%2fdouble-click-action-not-working-whereas-single-click-works-on-an-element-in-sele%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Wiesbaden

Marschland

Dieringhausen