Unable to locate element

Hi all,I’m trying to locate a text box element inside the form. Below is the html code
<form id=”answerForm-1 class=”ng-pristine ng-valid name=”answerForm>
<div class=”ng-scope ng-repeat=”question in value | orderBy: ‘crimson_question.crimson_order’>
<div class=”ng-scope ng-repeat=”question in value | orderBy: ‘crimson_question.crimson_order’>
<div class=”ng-scope ng-repeat=”question in value | orderBy: ‘crimson_question.crimson_order’>
<div id=”answerDiv-2>
<div>
<div class=”field-container>
<label class=”ng-binding ng-class=”{ asterisk: question.crimson_question.crimson_mandatory } for=”question.crimson_question>Please provide your full name:</label>
<div id=”answerLineDiv=2>
<div class=”ng-hide ng-hide=”true>
<input id=”answer-2 class=”ng-scope ng-pristine ng-valid data-answerid=”80e576fb-f00b-e811-811a-5065f38b0571 ng-if=”question.crimson_question.crimson_questiontype == ‘143570000’ || question.crimson_question.crimson_questiontype ==…… type=text>
My code to locate the element,
By formid = By.CssSelector(“form[id=answerForm-0]”);
IWebElement formelt = Driver.FindElement(formid);
IWebElement kycelt1 = formelt.FindElement(By.CssSelector(“#answer-2”));
kycelt1.sendkeys(“hi”);
can someone please help me to locate the element?
Thanks in advance.
Default Asked on February 7, 2018 in Selenium WebDriver.
Add Comment
  • 1 Answer(s)

    It might be because you are identifying element which is dynamic <input id=”answer-2″…/> . Please try reloading the webpage and then verify the id, if its dynamic then it should change to answer-n. Then I would suggest to identify it directly as below:

    By.CssSelector(“input[id(contains,’answer’)]”).sendKeys(“hi”);

     

    Default Answered on February 10, 2018.
    Add Comment
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.