Use XPath to found text row in query json - json

To introduce me : I'm not developer, and I want to control the element is present in my json.
I have this type of json, and i want to control for exemple that "id = display-page" but I don't know how can I structure of my xpath to found it
"text": "{\"id\":\"display-page\",\"recoVideo_hasRecoLoaded\":\"\",\"recovideo_requiredEngine\":\"tp1top\",\"recovideo_executedEngine\":\"tp1top\",\"recovideo_fallbackEngine\":\"\",\"recovideo_abtestEngine\":\"\",\"recovideo_recoVideoId\":\"top-video-web-desktop-windows-PERSONA_DEFAULT\"
I try something like $..request.text.[?(#.name =='id')].value.display-page
but it doesn't work :(
Someone to help me ?
Thanks !
Antoine

Related

Selecting some kind of closest child with jQuery seems not to work

I try to implement a nested tab module the following way.
By clicking on a .tabs__menu item I want to get the next .tabs__contents to display the correct entry.
I've prepared a codepen with markup and leave out all unimportant code so don't be irritated that it's not working. I don't understand why the variable debug2 is 0 and debug3 is 1. I expect debug2 to be 1 as well since I expect the following expression should find the element. Can anyone help me with this?:
.find(".tabs__contents").not(".tabs__contents .tabs__contents");
https://codepen.io/anon/pen/JNLWQp
Thanks in advance and best wishes,
duc
ok I have an assumption why it's not working. It seems that the .not method doesn't starts to search relatively from the given collection but globally. With this statement
.not(".tabs__contents .tabs__contents")
debug2 finds itself and exclude it from the collection thats why the length is 0.

Decriptive Programming Multiple properties

I am using to UFT and having a problem in describing multiple properties for an object.
b_username = "html id:=txtUsername","type:=text"
Trying this has not helped me. Even tried the ";" delimiter but that too is not working.
I think you have misunderstood how to reference an object using Descriptive Programming.
You still use the UFT syntax of Browser().Page().WebEdit() (for example) and because you are trying to set an object reference you need the Set keyword. Try something like:
Set b_username = Browser("micclass:=Browser").Page("micclass:=Page").WebEdit("html id:=txtUsername","type:=text")
This will allow you to use b_username to reference the text box with the html id of txtUsername:
b_username.Set myUsernameValue
For a pretty good basic introduction to descriptive programming, check out LearnQTP.com
What you are more closing attempting to do is to build a Description Object.
You need something like the following:
'Creating a description object
Set btncalc = Description.Create()
'Add descriptions and properties
btncalc("type").value = "Button"
btncalc("name").value = "calculate"
btncalc("html tag").value = "INPUT"
' Use the same to script it
Browser("Math Calc").Page("Num Calculator").WebButton(btncalc).Click
This SO article has a good explanation of a little more advanced technique.
How to create description object model at runtime in uft/qtp?
Please let me know if this clears up some confusion.
I would suggest you to use the below library for descriptive programming. It saves you from creating tons of descriptive objects. Check the usage in the link below.
http://www.testautomationguru.com/qtpuft-advanced-descriptive-programming/
To enter some value in the all the textboxes (no need to iterate)
Browser("creationTime:=0").Page("micclass:=Page").getChildObjects("micclass:=WebEdit").SetValue "1"
To enter some value in a textbox whose name starts with ‘guru’
Browser("creationTime:=0").Page("micclass:=Page").getChildObjects("micclass:=WebEdit,name:=guru.*").SetValue "1"
The above example can also be written as
Browser("creationTime:=0").Page("micclass:=Page").getChildObjects("micclass:=WebEdit").WithRegExProperty("name:=guru.*").SetValue "1"
To get the fifth visible child object which has the name as guru.
Browser("creationTime:=0").Page("micclass:=Page").getChildObjects("micclass:=WebEdit").WithRegExProperty("name:=guru.*").Index(4).Set "1"
To enter the values only in the visible text boxes
Browser("creationTime:=0").Page("micclass:=Page").getChildObjects("micclass:=WebEdit").WithRegExProperty("name:=guru.*").VisibleChildObjects.SetValue "1"
To select all visible check boxes
Browser("creationTime:=0").Page("micclass:=Page").getChildObjects("micclass:=WebCheckBox").VisibleChildObjects.SetValue "ON"
To get items count
Browser("creationTime:=0").Page("micclass:=Page").getChildObjects("micclass:=WebCheckBox,type:=checkbox,name:=jqg_list.*").VisibleChildObjects.getCount()
To match certain property values
Browser("creationTime:=0").Page("micclass:=Page").getChildObjects("micclass:=WebEdit").WithRegExProperty("name:=guru.*").VisibleChildobjects().Set "1"
To give some delay between 2 ‘Set’ – [if required for something]
Browser(“creationTime:=0”).Page(“micclass:=Page”).getChildObjects(“micclass:=WebEdit”).WithRegExProperty(“name:=guru.*”).VisibleChildobjects().DelayEachSetBy(1).Set “1”

Python - Return ID after finding Xpath with Selenium

I'm learning xpath and Selenium, and just successfully found the element I am trying to target. I am searching for a element where data-number = 48264
driver.find_element_by_xpath("//*[#data-number='48264']")
The HTML I am pulling from looks like this
<li id="pos_4" data-number="48264" class="top-item sellmid">
Now I am trying to return the ID "pos_4". I experimented with the below code, but it was totally wrong.
driver.find_element_by_xpath("//*[#data-asin='B01923Y7IG']").id
This returned a long float "0.066103113793198-1". Not sure what this is.
driver.find_element_by_xpath("//*[#data-asin='B01923Y7IG']").text
The above returned the text inside the div of the li.
Any suggestions on where to look next? I've done a lot of searching, but couldn't find anything helpful. Thanks!
you can do that by
ele = driver.find_element_by_xpath("//*[#data-number='48264']")
value = ele.get_attribute('id')
print value

AngularJS - Conditionally display key and value if they exist

This may be a little confusing to describe.
Basically, I am parsing multiple external JSON feeds that display in different views depending on the 'active tab' displayed. They both share the same partial template, so they both look exactly the same, just different content.
The problem that I am facing now is, that in some feeds, some keys are placed in an array and others are not.
For example, the feeds parses this kind of data:
JSON Feed 1 - One 'attributes' inside of 'link'
"link":{
"attributes":{
"href":"www.link1.com"
}
}
JSON Feed 2 - Two 'attributes' inside of 'link'
"link":[
{
"attributes":{
"href":"www.link1.com"
}
},
{
"attributes":{
"href":"www.link2.com"
}
}
]
The only way I am able to get the value "www.link1.com" is via:
For Feed 1:
link1
And for Feed 2:
link1
I am trying to figure out what would be the best way to do:
1) If link[0] exists - display it, else if [link] exists, display that instead.
2) Or if targeting the activeTab would be safer? For instance, if activeTab = view2 or view4, use [link][0], else if activeTab = view1 or view3 use [link], else if I do not want it to be displayed, do not display anything.
Also a relatable question, if I am on view2 can I only display [link][0] on that view?
Any feedback would be appreciated. Thanks!
In your model controller, you can reconstruct the JSON objects to make them similar. The value of link in both feeds should be an array.
Then in your template you can simply use ngRepeat to get the items from inside the array.
Okay - so I found a solution to one of the questions above: "How to only display [link][0] in a specific view"
Pro: It's a simple code that depends on the activeTab / view that is being displayed.
Con(?): Since I am really a newbie to AngularJS - not sure if this is the best solution.
Basically:
Depending on the ng-view that is currently displayed, than a specific JSON object will be displayed, such as:
<a ng-show="activeTab == 'view1' || activeTab == 'view3'" ng-href="{{item['link'][0]['attributes']['href']}}">
<h6>Link1 from Feed2</h6>
</a>
Although the primary question is still unresolved: How to swap/switch JSON objects (key,values) if one exists, and not the other. I am still definitely trying to find a solution, although any help is still appreciated.
Please let me know what you think, or how I can improve the solution to the problem!
Thanks!
Roc.

How to Display Array Value to through Index in DUSTJS

My Question is simple: Is there anyway to display array value through its index in DUSTjs syntax.
Sample JSON :
{ names:
[
"Jhon",
"Peter",
"Curly"
]
}
with the above json sample, I just want to display any of the names through its index in DUST syntax.
Note: We are able to display all names, but i need any of the names to be displayed as output through its index (Eg : names[0] something like this or by any other way).
when iterating $idx will give you the index so for example showing them as <li> elements:
{#names}
<li>
{names[$idx]}
<li>{~n}
{/names}
otherwise just plain
{names[1]}
will give you first element
This is quite easy to achieve:
{names[0]} gives you Jhon
{names[2]} gives you Curly
and so on.. Hope this helps.
if you use the linkedin dustjs fork, you can do that:
take a look here: http://linkedin.github.com/dustjs/test/test.html. There are a lot of examples.
This is the wikki: https://github.com/linkedin/dustjs/wiki
and this is the code repo:
https://github.com/linkedin/dustjs