Forum Discussion

lambada's avatar
lambada
Contributor
6 years ago
Solved

SetText

Dear community

 

For my login (in java script) I am using the following script, that includes SetText. But when I am using SetText, the testcase will fail because of "run time error". Does anybody has a guess why this error appears and can anybody please help me?

 

The script can click at the login button without any problems and it works. The problems are just setting username and password.

 

 

 

function login() {


var url = "http://.../login";

 

var UserName_XPath        = "//input[@class=..................@ng-class=\"{error: error}\"]";
var PassWord_XPath         = "//input[@class=\..........and @ng-class=\"{error: error}\"]";
var LogInButton_XPath    = "//button[@type=\..............................................\"Log In\"]";

 

var username, password, loginButton;

Browsers.Item(btChrome).Run(url);
var page = Sys.Browser("*").Page(url);
Sys.Browser().BrowserWindow(0).Maximize();

aqUtils.Delay(3000);

username = page.FindChildByXPath(UserName_XPath, true);
password = page.FindChildByXPath(PassWord_XPath, true);
loginButton = page.FindChildByXPath(LogInButton_XPath, true);

username.SetText("lambada");
password.SetText("five");

loginButton.Click();

page.Wait();

}

 

 

  • I solved the problem now. I have had taken the whole hudge XPath, and there were some issues with it. Now I used an extension and got a shorter XPath and now it is working.

     

    Thank you for your help :)

6 Replies

  • shankar_r's avatar
    shankar_r
    Community Hero

    If you have problems with SetText then try Keys() method which will do the same.

     

    username.Keys("lambada");
    password.Keys("five")

    • lambada's avatar
      lambada
      Contributor

      Thank you very much!

       

      I just tried it but I´ve got again the same error :smileyindifferent:

  • I solved the problem now. I have had taken the whole hudge XPath, and there were some issues with it. Now I used an extension and got a shorter XPath and now it is working.

     

    Thank you for your help :)

    • tristaanogre's avatar
      tristaanogre
      Esteemed Contributor

      lambada wrote:

      I solved the problem now. I have had taken the whole hudge XPath, and there were some issues with it. Now I used an extension and got a shorter XPath and now it is working.

       

      Thank you for your help :)


      This is the drawback for using XPath for finding objects.  Many times what is returned by an XPath find is not a UI object recognized by TestComplete and, therefore, will not have either the Keys or SetText method.  This will generate an error, then, if you try and use one of those methods with what is returned.

       

      Additionally... XPath searching scans the whole DOM which takes time.  TestComplete's NameMapping feature is the preferred and recommended way for object identification.  

      • lambada's avatar
        lambada
        Contributor

        Thank you very much!

         

        Could you plese make a very short example in my case with the NameMapping feature?