Clearing Text value by Javascript Executor and Actions are NOT working!- Selenium











up vote
0
down vote

favorite












Im trying to clear the Existing value of a field[TextBox]by the folowing ways,




  1. Action - MoveToElement - Keys.Backspace

  2. Selenium method - Clear()


everytime: used to get the same error message :No such elementexception though the element identification is correct and even i tried to focus the element before performing the action but still failed.



suggest me the approach please



note: Microsoft.Dynamics CRM application










share|improve this question






















  • please post a snippet of your HTML including the element which you are trying to clear. Is the element contained within a frame or iframe?
    – Ryan Wilson
    Nov 21 at 19:50










  • No such element == you have wrong locator.
    – Vladimir Efimov
    Nov 21 at 19:50








  • 1




    @VladimirEfimov It's possible the locator is correct but the element is inside a frame, iframe document. If it's inside a frame or iframe, the driver needs to be moved to the frame document for it to be able to find the element.
    – Ryan Wilson
    Nov 21 at 19:51












  • @RyanWilson yep, good addition makes sense... but anyway stan says that he was able to "focus" an element whetever that means... probably 'focus' it via browser inspector.
    – Vladimir Efimov
    Nov 21 at 19:52






  • 1




    when i enter the value for the first time - selenium ables to identify the element BUT when i access the same element for clearing the value - selenium fails to locate it and throws the error! @RyanWilson
    – stan
    Nov 21 at 20:36















up vote
0
down vote

favorite












Im trying to clear the Existing value of a field[TextBox]by the folowing ways,




  1. Action - MoveToElement - Keys.Backspace

  2. Selenium method - Clear()


everytime: used to get the same error message :No such elementexception though the element identification is correct and even i tried to focus the element before performing the action but still failed.



suggest me the approach please



note: Microsoft.Dynamics CRM application










share|improve this question






















  • please post a snippet of your HTML including the element which you are trying to clear. Is the element contained within a frame or iframe?
    – Ryan Wilson
    Nov 21 at 19:50










  • No such element == you have wrong locator.
    – Vladimir Efimov
    Nov 21 at 19:50








  • 1




    @VladimirEfimov It's possible the locator is correct but the element is inside a frame, iframe document. If it's inside a frame or iframe, the driver needs to be moved to the frame document for it to be able to find the element.
    – Ryan Wilson
    Nov 21 at 19:51












  • @RyanWilson yep, good addition makes sense... but anyway stan says that he was able to "focus" an element whetever that means... probably 'focus' it via browser inspector.
    – Vladimir Efimov
    Nov 21 at 19:52






  • 1




    when i enter the value for the first time - selenium ables to identify the element BUT when i access the same element for clearing the value - selenium fails to locate it and throws the error! @RyanWilson
    – stan
    Nov 21 at 20:36













up vote
0
down vote

favorite









up vote
0
down vote

favorite











Im trying to clear the Existing value of a field[TextBox]by the folowing ways,




  1. Action - MoveToElement - Keys.Backspace

  2. Selenium method - Clear()


everytime: used to get the same error message :No such elementexception though the element identification is correct and even i tried to focus the element before performing the action but still failed.



suggest me the approach please



note: Microsoft.Dynamics CRM application










share|improve this question













Im trying to clear the Existing value of a field[TextBox]by the folowing ways,




  1. Action - MoveToElement - Keys.Backspace

  2. Selenium method - Clear()


everytime: used to get the same error message :No such elementexception though the element identification is correct and even i tried to focus the element before performing the action but still failed.



suggest me the approach please



note: Microsoft.Dynamics CRM application







c# selenium-webdriver dynamics-crm






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 at 19:48









stan

206




206












  • please post a snippet of your HTML including the element which you are trying to clear. Is the element contained within a frame or iframe?
    – Ryan Wilson
    Nov 21 at 19:50










  • No such element == you have wrong locator.
    – Vladimir Efimov
    Nov 21 at 19:50








  • 1




    @VladimirEfimov It's possible the locator is correct but the element is inside a frame, iframe document. If it's inside a frame or iframe, the driver needs to be moved to the frame document for it to be able to find the element.
    – Ryan Wilson
    Nov 21 at 19:51












  • @RyanWilson yep, good addition makes sense... but anyway stan says that he was able to "focus" an element whetever that means... probably 'focus' it via browser inspector.
    – Vladimir Efimov
    Nov 21 at 19:52






  • 1




    when i enter the value for the first time - selenium ables to identify the element BUT when i access the same element for clearing the value - selenium fails to locate it and throws the error! @RyanWilson
    – stan
    Nov 21 at 20:36


















  • please post a snippet of your HTML including the element which you are trying to clear. Is the element contained within a frame or iframe?
    – Ryan Wilson
    Nov 21 at 19:50










  • No such element == you have wrong locator.
    – Vladimir Efimov
    Nov 21 at 19:50








  • 1




    @VladimirEfimov It's possible the locator is correct but the element is inside a frame, iframe document. If it's inside a frame or iframe, the driver needs to be moved to the frame document for it to be able to find the element.
    – Ryan Wilson
    Nov 21 at 19:51












  • @RyanWilson yep, good addition makes sense... but anyway stan says that he was able to "focus" an element whetever that means... probably 'focus' it via browser inspector.
    – Vladimir Efimov
    Nov 21 at 19:52






  • 1




    when i enter the value for the first time - selenium ables to identify the element BUT when i access the same element for clearing the value - selenium fails to locate it and throws the error! @RyanWilson
    – stan
    Nov 21 at 20:36
















please post a snippet of your HTML including the element which you are trying to clear. Is the element contained within a frame or iframe?
– Ryan Wilson
Nov 21 at 19:50




please post a snippet of your HTML including the element which you are trying to clear. Is the element contained within a frame or iframe?
– Ryan Wilson
Nov 21 at 19:50












No such element == you have wrong locator.
– Vladimir Efimov
Nov 21 at 19:50






No such element == you have wrong locator.
– Vladimir Efimov
Nov 21 at 19:50






1




1




@VladimirEfimov It's possible the locator is correct but the element is inside a frame, iframe document. If it's inside a frame or iframe, the driver needs to be moved to the frame document for it to be able to find the element.
– Ryan Wilson
Nov 21 at 19:51






@VladimirEfimov It's possible the locator is correct but the element is inside a frame, iframe document. If it's inside a frame or iframe, the driver needs to be moved to the frame document for it to be able to find the element.
– Ryan Wilson
Nov 21 at 19:51














@RyanWilson yep, good addition makes sense... but anyway stan says that he was able to "focus" an element whetever that means... probably 'focus' it via browser inspector.
– Vladimir Efimov
Nov 21 at 19:52




@RyanWilson yep, good addition makes sense... but anyway stan says that he was able to "focus" an element whetever that means... probably 'focus' it via browser inspector.
– Vladimir Efimov
Nov 21 at 19:52




1




1




when i enter the value for the first time - selenium ables to identify the element BUT when i access the same element for clearing the value - selenium fails to locate it and throws the error! @RyanWilson
– stan
Nov 21 at 20:36




when i enter the value for the first time - selenium ables to identify the element BUT when i access the same element for clearing the value - selenium fails to locate it and throws the error! @RyanWilson
– stan
Nov 21 at 20:36












1 Answer
1






active

oldest

votes

















up vote
1
down vote













Based on additional data from comments here is what probably happens:




  1. You get an instance of WebElement - there is an element matching your locator at that moment of time

  2. You enter some value to the element - this action most likely changes your web element somehow (e.g. changes style/class/or even a tag)

  3. You trying to get an instance of the same WebElement using the same locator and NoSuchElementException is thrown - this is because the element is now not exactly the same as in step 1


If you add sample HTML before entering text and after the text is entered we probably will be able to provide the exact solution.



As of now I can suggest 2 ways:




  1. When you want to clear the text - you need to use different locator. That will match exactly the element you need to work with.

  2. If your page does not reload after you type text, you just can create a variable for WebElement, find element and store it to the variable before entering the text, then work with this variable enter a text using sendKeys, then clear text applying clear method to this same variable. I.e. it might be that you don't really need to call findElement twice if the page stays the same.






share|improve this answer

















  • 1




    problem is focus is not on the element. driver was referring another page after switching to the current page i was able get the handle of webelement.
    – stan
    Nov 24 at 19:27










  • many thanks for providing nice explanation and suggestions
    – stan
    Nov 24 at 19:28











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',
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%2f53419528%2fclearing-text-value-by-javascript-executor-and-actions-are-not-working-seleniu%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote













Based on additional data from comments here is what probably happens:




  1. You get an instance of WebElement - there is an element matching your locator at that moment of time

  2. You enter some value to the element - this action most likely changes your web element somehow (e.g. changes style/class/or even a tag)

  3. You trying to get an instance of the same WebElement using the same locator and NoSuchElementException is thrown - this is because the element is now not exactly the same as in step 1


If you add sample HTML before entering text and after the text is entered we probably will be able to provide the exact solution.



As of now I can suggest 2 ways:




  1. When you want to clear the text - you need to use different locator. That will match exactly the element you need to work with.

  2. If your page does not reload after you type text, you just can create a variable for WebElement, find element and store it to the variable before entering the text, then work with this variable enter a text using sendKeys, then clear text applying clear method to this same variable. I.e. it might be that you don't really need to call findElement twice if the page stays the same.






share|improve this answer

















  • 1




    problem is focus is not on the element. driver was referring another page after switching to the current page i was able get the handle of webelement.
    – stan
    Nov 24 at 19:27










  • many thanks for providing nice explanation and suggestions
    – stan
    Nov 24 at 19:28















up vote
1
down vote













Based on additional data from comments here is what probably happens:




  1. You get an instance of WebElement - there is an element matching your locator at that moment of time

  2. You enter some value to the element - this action most likely changes your web element somehow (e.g. changes style/class/or even a tag)

  3. You trying to get an instance of the same WebElement using the same locator and NoSuchElementException is thrown - this is because the element is now not exactly the same as in step 1


If you add sample HTML before entering text and after the text is entered we probably will be able to provide the exact solution.



As of now I can suggest 2 ways:




  1. When you want to clear the text - you need to use different locator. That will match exactly the element you need to work with.

  2. If your page does not reload after you type text, you just can create a variable for WebElement, find element and store it to the variable before entering the text, then work with this variable enter a text using sendKeys, then clear text applying clear method to this same variable. I.e. it might be that you don't really need to call findElement twice if the page stays the same.






share|improve this answer

















  • 1




    problem is focus is not on the element. driver was referring another page after switching to the current page i was able get the handle of webelement.
    – stan
    Nov 24 at 19:27










  • many thanks for providing nice explanation and suggestions
    – stan
    Nov 24 at 19:28













up vote
1
down vote










up vote
1
down vote









Based on additional data from comments here is what probably happens:




  1. You get an instance of WebElement - there is an element matching your locator at that moment of time

  2. You enter some value to the element - this action most likely changes your web element somehow (e.g. changes style/class/or even a tag)

  3. You trying to get an instance of the same WebElement using the same locator and NoSuchElementException is thrown - this is because the element is now not exactly the same as in step 1


If you add sample HTML before entering text and after the text is entered we probably will be able to provide the exact solution.



As of now I can suggest 2 ways:




  1. When you want to clear the text - you need to use different locator. That will match exactly the element you need to work with.

  2. If your page does not reload after you type text, you just can create a variable for WebElement, find element and store it to the variable before entering the text, then work with this variable enter a text using sendKeys, then clear text applying clear method to this same variable. I.e. it might be that you don't really need to call findElement twice if the page stays the same.






share|improve this answer












Based on additional data from comments here is what probably happens:




  1. You get an instance of WebElement - there is an element matching your locator at that moment of time

  2. You enter some value to the element - this action most likely changes your web element somehow (e.g. changes style/class/or even a tag)

  3. You trying to get an instance of the same WebElement using the same locator and NoSuchElementException is thrown - this is because the element is now not exactly the same as in step 1


If you add sample HTML before entering text and after the text is entered we probably will be able to provide the exact solution.



As of now I can suggest 2 ways:




  1. When you want to clear the text - you need to use different locator. That will match exactly the element you need to work with.

  2. If your page does not reload after you type text, you just can create a variable for WebElement, find element and store it to the variable before entering the text, then work with this variable enter a text using sendKeys, then clear text applying clear method to this same variable. I.e. it might be that you don't really need to call findElement twice if the page stays the same.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 22 at 5:53









Vladimir Efimov

655311




655311








  • 1




    problem is focus is not on the element. driver was referring another page after switching to the current page i was able get the handle of webelement.
    – stan
    Nov 24 at 19:27










  • many thanks for providing nice explanation and suggestions
    – stan
    Nov 24 at 19:28














  • 1




    problem is focus is not on the element. driver was referring another page after switching to the current page i was able get the handle of webelement.
    – stan
    Nov 24 at 19:27










  • many thanks for providing nice explanation and suggestions
    – stan
    Nov 24 at 19:28








1




1




problem is focus is not on the element. driver was referring another page after switching to the current page i was able get the handle of webelement.
– stan
Nov 24 at 19:27




problem is focus is not on the element. driver was referring another page after switching to the current page i was able get the handle of webelement.
– stan
Nov 24 at 19:27












many thanks for providing nice explanation and suggestions
– stan
Nov 24 at 19:28




many thanks for providing nice explanation and suggestions
– stan
Nov 24 at 19:28


















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.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • 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%2f53419528%2fclearing-text-value-by-javascript-executor-and-actions-are-not-working-seleniu%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

Berounka

Sphinx de Gizeh

Different font size/position of beamer's navigation symbols template's content depending on regular/plain...