Ask a Question

SetText

SOLVED
lambada
Contributor

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();

}

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
lambada
Contributor

Re: SetText

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 πŸ™‚

View solution in original post

6 REPLIES 6
shankar_r
Community Hero

Re: SetText

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

 

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


Thanks
Shankar R

LinkedIn | CG-VAK Software | Bitbucket | shankarr.75@gmail.com

β€œYou must expect great things from you, before you can do them”

Extension Available

lambada
Contributor

Re: SetText

Thank you very much!

 

I just tried it but IΒ΄ve got again the same error Smiley Indifferent

lambada
Contributor

Re: SetText

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 πŸ™‚

View solution in original post

tristaanogre
Community Hero

Re: SetText


@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.  


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
lambada
Contributor

Re: SetText

Thank you very much!

 

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

tristaanogre
Community Hero

Re: SetText

Since I don't know your application, everything is going to be in generic terms.

function Login(userName, password){
try{
Sys.Browser('chrome').Run('http://myserver.myapp/')'
var myPage = Aliases.browser.WaitAliasChild('pageLogin', -1);
if (!myPage.Exists){
    throw Error('Login page did not load in time');
}
myPage.userName.SetText(userName);
myPage.password.Keys(password);
myPage.LoginButton.ClickButton();
var myPage = Aliases.browser.WaitAliasChild('landingPage', -1);
if (!myPage.Exists){
    throw Error('Primary landing page after login did not load in time');
}

}

}

Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
cancel
Showing results forΒ 
Search instead forΒ 
Did you mean:Β