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;
}
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;"> * Quarter to 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
|
show 1 more comment
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;"> * Quarter to 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
@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
|
show 1 more comment
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;"> * Quarter to 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
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;"> * Quarter to 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
java selenium xpath css-selectors double-click
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
|
show 1 more comment
@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
|
show 1 more comment
3 Answers
3
active
oldest
votes
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();
Tried even that but nothing seems to work. Is there any other way to double click?
– Ayisha
Nov 26 '18 at 18:41
add a comment |
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"));
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
add a comment |
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);
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 todoubleClick()
instead of aclick()
– 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
|
show 6 more comments
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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();
Tried even that but nothing seems to work. Is there any other way to double click?
– Ayisha
Nov 26 '18 at 18:41
add a comment |
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();
Tried even that but nothing seems to work. Is there any other way to double click?
– Ayisha
Nov 26 '18 at 18:41
add a comment |
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();
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();
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
add a comment |
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
add a comment |
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"));
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
add a comment |
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"));
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
add a comment |
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"));
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"));
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
add a comment |
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
add a comment |
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);
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 todoubleClick()
instead of aclick()
– 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
|
show 6 more comments
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);
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 todoubleClick()
instead of aclick()
– 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
|
show 6 more comments
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);
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);
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 todoubleClick()
instead of aclick()
– 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
|
show 6 more comments
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 todoubleClick()
instead of aclick()
– 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
|
show 6 more comments
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
@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