cancel
Showing results for 
Search instead for 
Did you mean: 

QuerySelector

SOLVED
Highlighted
Valued Contributor

QuerySelector

Hi,

I'm new to this feature, I would like to identify an object to use the "SetText()" or "Key()" method on it.

 

Could Someone tell me what should I write in CSSSelector to identify this object ?

(The identifier is "sMatricule")

 

Thank you !

 

queryselector.PNG

2 ACCEPTED SOLUTIONS

Accepted Solutions
Valued Contributor

Re: QuerySelector

I finally found it :

 

Sys.Browser().Page('*').QuerySelector('[data-bind="value: sMatricule"]').SetText('test');

View solution in original post

Highlighted
Community Hero

Re: QuerySelector

Hi,

 

a) Robert is correct with his note. Any reason not to use Aliases.browser.page ?

b) Exactly as I said (without knowing your tested application details) - button click reloads the page, but your code does not wait for page to load and looks for the object. As the object does not exist yet, the search fails.

At least, I would recommend to execute

Aliases.browser.page.Wait()

after the click to wait for the page to load. Depending on your tested application, additional delays might be required to wait for page scripts and relevant Ajax calls to complete.

 

Regards,
Alex
[Community Expert Group]
____
[Community Expert Group] members are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Postings made by [Community Expert Group] members
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
[Community Expert Group] signature is used with permission by SmartBear Software.
http://smartbear.com/forums/f83/t86934/community-experts/
================================

View solution in original post

10 REPLIES 10
Valued Contributor

Re: QuerySelector

I finally found it :

 

Sys.Browser().Page('*').QuerySelector('[data-bind="value: sMatricule"]').SetText('test');

View solution in original post

Highlighted
Valued Contributor

Re: QuerySelector

Hi,

I don't understand something :

I write my script with the following code :

 

Sys.Browser().Page('*').QuerySelector('[data-bind="value: sMatricule"]').SetText('00052');

 

And when I close the browser, re-open it I try to replay the script it says "Undeclared identifier: SetText".

 

Anyone has an idea ?

 

Thanks,

Highlighted
Valued Contributor

Re: QuerySelector

Up... any help please ? Thank you !

Highlighted
Community Hero

Re: QuerySelector

Hi,

 

"Undeclared identifier: SetText"

This means that the sought for object (.QuerySelector('[data-bind="value: sMatricule"]')) was not found, .QuerySelector() returned null and thus runtime engine failed to reference the SetText identifier.

 

Regards,
Alex
[Community Expert Group]
____
[Community Expert Group] members are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Postings made by [Community Expert Group] members
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
[Community Expert Group] signature is used with permission by SmartBear Software.
http://smartbear.com/forums/f83/t86934/community-experts/
================================
Highlighted
Community Hero

Re: QuerySelector

What browser are you using?

 

One thing I've noticed is that when you close a browser in windows, sometimes there's an instance of the browser that hangs out in memory.  I've seen this with Chrome and IE.  So, your code is very non-specific.  You're not specifying a particular browser or browser instance.  Nor are you designated a specific page.  So, when you close down and re-open and try and run again, if there is any residual memory instance of a web browser, you could very well be finding absolutely nothing.

 

You should get in the habit of specifying better details in the code to indicate both browser and page you're operating against.  I've also made it a point in any web automation I do that, when starting up a test, I scan the processes in memory for any browser instances, kill them, and then re-launch the browser via code and make sure that browser instance is what I'm using in my code.


Robert Martin
[Community Expert Group]
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
Highlighted
Valued Contributor

Re: QuerySelector

Hey Robert, thanks for helping !

 

I'm using ie.

 

I may precise a little bit more my problem :

When I play the whole sequence (I mean, go to the desired webpage and act on edit components with QuerySelector) it goes well to the page and then gives me this error message.

But when I'm on the web page, and if I execute the line alone, it works !

I don't catch the difference...

 

Here is what I execute from the menu :

 

querySelector.png

Highlighted
Community Hero

Re: QuerySelector

Why aren't you using Aliases.browser.pageXXXXX.QuerySelector? 

The reason I ask is that ie sometimes opens multiple instances in Windows... and so there may be blank pages and such out there that are in different indexed instances of IE.  


Robert Martin
[Community Expert Group]
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
Highlighted
Community Hero

Re: QuerySelector

Hi,

 

a) Robert is correct with his note. Any reason not to use Aliases.browser.page ?

b) Exactly as I said (without knowing your tested application details) - button click reloads the page, but your code does not wait for page to load and looks for the object. As the object does not exist yet, the search fails.

At least, I would recommend to execute

Aliases.browser.page.Wait()

after the click to wait for the page to load. Depending on your tested application, additional delays might be required to wait for page scripts and relevant Ajax calls to complete.

 

Regards,
Alex
[Community Expert Group]
____
[Community Expert Group] members are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Postings made by [Community Expert Group] members
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
[Community Expert Group] signature is used with permission by SmartBear Software.
http://smartbear.com/forums/f83/t86934/community-experts/
================================

View solution in original post

Highlighted
Community Hero

Re: QuerySelector

@AlexKaras wrote

b) Exactly as I said (without knowing your tested application details) - button click reloads the page, but your code does not wait for page to load and looks for the object. As the object does not exist yet, the search fails. At least, I would recommend to execute Aliases.browser.page.Wait() after the click to wait for the page to load. Depending on your tested application, additional delays might be required to wait for page scripts and relevant Ajax calls to complete.
I didn't even catch that. Yeah, that would be EXACTLY why it only works if you run just the line. Good catch!

Robert Martin
[Community Expert Group]
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