1

I know this is going to be a rookie question, but I've spent 2 days on this and I'm desperate.

There are two textboxes on a page I need to populate. They are:

<input type="text" ng-model="searchCtrl.name" placeholder="Name or CRD#" flex="auto" class="ng-pristine ng-untouched ng-valid flex-auto ng-empty" aria-invalid="false">

and

<input type="text" id="firm-input" ng-model="searchCtrl.firm" placeholder="Firm Name or CRD# (optional)" flex="auto" class="ng-pristine ng-untouched ng-valid flex-auto ng-empty" aria-invalid="false">

I can populate the 2nd textbox using:

driver.FindElement(By.Id("acIndividualLocationId")).SendKeys("Sugar Grove, IL");

But as you can see, there is no ID or NAME for the 1st textbox. And I cannot get the CssSelector, TagName, or XPath to work (not sure why).

I can populate the 2nd textbox, THEN move the focus to the 1st textbox by:

driver.FindElement(By.Id("acIndividualLocationId")).SendKeys(Keys.Shift + Keys.Tab);

So here's the rub: how do I populate the 1st textbox now that I have the focus on it???

ENVIRONMENT:

  • Windows 10
  • Visual Studio 2019
  • C#
  • Selenium.WebDriver 3.141.0
  • Selenium.WebDriver.ChromeDriver 83.0.4103.3900

Thanks in advance…

3

1 Answer 1

1

I understand Your filling So many time i face this kind of issue specially when angular is there and finally i found one solution.

here you can use Xpath or use Javascript.

1.using Javascript :

    var script = @" try{
                            var appEleWrap = document.getElementsByClassName(Your class name);
                            setTimeout(function(){
                                scopeWrap = angular.element(appEleWrap).scope();
                                if(!scopeWrap.$$phase){
                                    scopeWrap.$apply(function(){
                                        scopeWrap.searchCtrl.name = '{0}';
                                        scopeWrap.searchCtrl.firm='{1}';
                                     }); 
                                }
                            }, 1000);
                          }catch(e){ alert(e.message); }
                      ";
        string evalScript = string.Empty;
        evalScript = script.Replace("{0}", "Your Text");
        evalScript = evalScript.Replace("{1}", "Your Text");
        IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
        js.ExecuteScript(evalScript);

2.using Xpath : find List of element. based on index you can populate text box

var ListOfElm = driver.FindElements(By.XPath("//input[contains(@type,'text')]")).ToList();
        if (ListOfElm != null)
        {
            ListOfElm[0].SendKeys("");//Based on index ok.
            ListOfElm[1].SendKeys("");
        }

I hope this will help you Thank You.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you Amar. I used your solution #2. Gave me exactly what I needed. I'm new to Windows desktop programming - years of IBM mainframes and ASP.Net, but this is a challenge. I definitely need a better understanding of XPath...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.