How to identify HTML object by it's style in HP QTP? - automated-tests

I have a web app and two objects with same class name (no IDs), other attributes also the same. The difference only in same style attributes: one of the objects has "style.display='block'", other has "style.display='none'". (could be other styles attributes!)
How I can identify first object by it's style attributes? For thing such names, I could use "attribute/name", but is there anything like this for style?
Thank you!

Edit: My original answer was true for its time but UFT has since added support for style/ properties. You can now use style/display:=none".
This is indeed a limitation in QTP :(
One thing you can do is write a small WebExtesibility project which adds the display property to your test object.

I know this is an old question, but it is accepted as if there is not a simple solution for it, while there is:
Yes you can, but it has to be an attribute on the actual object and not inherited by parent objects (well, I had negative results on that situation).
' Make a new description for the object
Set desc = Description.Create()
desc("micclass").Value = "WebButton" ' assuming webbutton here
desc("Class Name").Value = "YourClassName"
' This returns a collection with buttons matching your description
Set Btns = Browser("YourBrowser").Page("YourPage").ChildObjects(desc)
For BtnIndex = 0 to Btns.Count - 1
' This will show you the display style, so you can make a selector here
MsgBox "Button " & BtnIndex & " has display style: " & Btns(BtnIndex).Object.currentStyle.Display
Next

Related

Ignition 7.8 – Get Component Text From Text Area Within Container Via Scripting

A Button with scripting is saving Component values to parameters for a SQL update. The calling button is one level above the Container that holds the Text Area. However, the set for the Text Area value using the recommended User Manual method is throwing the error “AttributeError: 'NoneType' object has no attribute 'text' “
Standard form not working:
Comments = event.source.parent.getComponent('textArea1).text
Also tried different attributes at the end of the call:
… .string , … .value , … .stringvalue
event.source.parent.parent.getComponent('textArea1).text
When looking at the Property Binding path on the Component, I am able to return “Root Container. ContainerName.textArea1.text”. When I modified to be a GetProperty pull like below, I received a similar error mixed with an add on of Selected Property Not Found. I tried similar alternatives to those listed above.
Comments = event.source.parent.ContainerName.getComponent('textArea1).text
Any suggestions?
The solution is to call the Container component by name using the ‘.getComponent’ method and then call the Text Area using the standard method. The combined code is below for setting to the Parameter Comments.
Comments = event.source.parent.parent.getComponent('ContainerName').getComponent('TextArea1').text
Retrieving a Component value from within a Container does not appear to be covered in the Ignition Manual.

Qt: how to save QTextEdit contents with custom properties

I have a text editor (QTextEdit). Some words in my editor contains additional information attached (namely, two corresponding integer positions in wave file for that word).
They are stored in Python object as custom properties for QTextCharFormat objects (I attach them with code like this: self.editor.textCursor().setCharFormat(QTextCharFormat().setProperty(MyPropertyID, myWordAttachment) )
Unfortunately, if I save my document to html, all of that additional formatting is lost.
So, I want to perform simplest task: to save my document with all of it's formatting,including myWordAttachment (and to load it from disk).
Am I right that Qt5 doesn't have something ready for it, and I have to write all that document's serialization code by myself? (I still hope that where is simple function that did the job)
1.you loop your text every character.
2.and you catch the character and its charFormat()
3.and you get the properties.
4.Because the properties are eventually a value of something, int,str,...
So you get the properties by charFormat().property(1),(2),(3)... or properties()
5.The most important thing is the character's position & the range.You get the position during the 1th loop.
6.When you catch the CharFormats, you insert into something hashable object like list.
& and you don't forget to insert the CharFormats position.
6.you save your document and the position & properties.
My suggestion for your solution.
1.you can get characterCount() by the QTextDocument object.
2.you loop the range of the characterCount()
3.Before doing it, you make a QTextCursor object.
4.you set the textcursor at the first position.(movePosition method & Start moveoperation & KeepAnchor flag)
5.you move the cursor to right one character & Another.
6.you check the character's charFormat() by tc.charFormat() and the tc.position()
7.But it is the time to Think twice. CharFormat is always the bunch of characters.
you probably get some characters of the same CharFormat().
You can prepare for it.I can Think about some way,but... you should set the QCharFormat objectType or propertyId() for specifing the QCharFormat in Advance(during editing your document).Why don't you set the texts into the properties for after saving & loading.I hope you manage to pass here during debugging & tring.
8.if you get a charFormat,and you check the objectType().
9.if the objectType() is the same as Before searched, you pass the search engine without doing anything.
10.The second important thing is that calls clearSelection() each searching.
11.You save your document() as it is html strings.and you save the charFormats() properties.
12.when you load your document(),the html sentence comes back.
and load the properties.
you make QTextCursor and setPosition( the property's position saved in advance.)
you move QTextCursor until the position and you select the target texts.
you adopt the charFormat properties again and the end.
Summary
The important thing how you specify the charFormat().
You can catch the charFormat without any problem.but the charFormat() is adopted in some range.So you must distinguish the range.
1.The targeted texts is set in the QTextCharFormat's property.
2.You have The QTextCursor pass during the same QTextCharFormat's object.
I can Think of them...
I Think it is some helps for you.

Alternative of contains in cssSelector ? Selenium WebDriver

I am using selenium 2 (WebDriver).
I am locating a button and clicking by the script:
driver.findElement(By.cssSelector("button:contains('Run Query')"));
or
driver.findElement(By.cssSelector("css=.gwt-Button:contains('Run Query')"))
whose html is like :
<button type="button" class="gwt-Button" id="ext-gen362">Run Query</
button>
As the id is dynamically generated, I can't make use of the ID.
Is there any way to use cssSelector with something like contains ? Is this possible?
You can't do this with CSS selectors, because there is no such thing as :contains() in CSS. It was a proposal that was abandoned years ago.
If you want to select by the element text, you'll have use an XPath selector. Something like
driver.findelement(By.xpath("//button[contains(., 'Run Query']"))
or
driver.findelement(By.xpath("//[contains(concat(' ', #class, ' '), ' .gwt-Button ') and contains(., 'Run Query']"))
Another option is using jQuery, if it's present on the page, something like:
var webElement = ((JavascriptExecutor)driver).executeScript("return jQuery('button:contains(Run Query)')");
CSS alone will not get you what you need; you cannot filter by the text. You could either use js to get the id of the element, or loop through all the buttons in your code until you find the one with the right text. If this were in python:
[btn for btn in browser.find_elements_by_css_selector('button')
if 'Run Query' in btn.text]
You could easily generalize this and make a helper function, too.
I'm in the same boat, currently using XPath selectors with "contains" to find elements with specific text content. Some are <td> and some are <td><a> deep within large tables (specific columns, but row unknown in advance). It's very slow (4 to 5 seconds just to find such a table entry with Firefox 20), so I was hoping to use CSS to be faster. Often the text will be by itself (complete) and other times it will be a filename at the end of a path I'd like to ignore. Does anyone have suggestions for the fastest XPath search pattern, given that it's a known column but unknown row, and may be a <td> or <td><a> (sometimes in the same table). Would an equality comparison be much faster than contains(), for the majority of cases where the text I'm looking for is complete (not at the end of other text)? I think there's a "starts with" lookup, but is there an "ends with" lookup? I know that using an "id" would be even faster, but unfortunately this HTML doesn't have any IDs here, and they can't be added. I'm looking to find the <tr> containing this text so I can locate another element in the same row and get its text or click on a link. It doesn't hurt to locate a small subset of the rows and check their text, but I'd like to avoid doing separate searches for <td> and <td><a> if that's possible.
You cannot use contains but use a wild card instead.
driver.findElement(By.cssSelector("button:(*'Run Query'*)"));
driver.findElement("#ext-gen362").Where(webElement => webElement.Text.Contains("Run Query"))

Keyword Path in SDL Tridion

Could someone please give some idea on how this can be done? This might be very simple and basics, but i couldn't figure this out.
Here is my requirement.
I have a category A with child keyword B and B got another Child Keyword C.
I want to get the exact path of selected keyword in my component template,Say for eg, if user selects keyword C, i need the value with path like A\B\C and not just as C. But Tridion always gives me the value as C and not as A\B\C . Component Schema is using "Tree" view to select the keywords.
Should I be writing dreamweaver custom functions to handle this? Or does tridion comes with some handler for this?
Any help would be highly appreciated. Thank you!
Thanks,
KK
As you just found out, the Tridion Keyword Hierarchy is "fake" - Keywords are stored as a flat list, not as a hierarchical list (like you would have with folders). The information about the parent and children keywords is stored in the keyword itself.
There are solutions for this - of course, for instance you can use this in a C# TBB:
Keyword keyword = new Keyword(new TcmUri("tcm:28-3368-1024"), session);
string hierarchy = keyword.Title;
bool done = false;
while(!done)
{
if (keyword.ParentKeywords.Count > 0)
{
foreach (Keyword k in keyword.ParentKeywords)
{
hierarchy = k.Title + " > " + hierarchy;
}
keyword = keyword.ParentKeywords[0];
}
else
done = true;
}
// Include Category
hierarchy = keyword.OrganizationalItem.Title + " > " + hierarchy;
EDIT: Updated to recursively "go up" the hierarchy. HOWEVER a keyword can have multiple parents, I'll leave that up to you to fix...
Keywords within a category are unique, so Tridion can safely refer to them by their name (and/or their TCM URI of course). And since a Keyword can have multiple parents, there may not be a single path leading from the root to your Keyword.
If in your situation the category can be represented as a tree, you can of course build a single path to each keyword. In that case you'll need some (C#) code that walks up the parents axis and concatenates the names. You can put this code either:
in a TBB that you put into your template before the DWT OR
in a custom Dreamweaver function.
Either way will work fine.

2 Mutually exclusive RadioButton "Lists"

I think this has to be THE most frustrating thing I've ever done in web forms. Yet one would think it would be the easiest of all things in the world to do. That is this:
I need 2 separate lists of radiobuttons on my .aspx page. One set allows a customer to select an option. The other set does also but for a different purpose. But only one set can have a selected radiobutton.
Ok I've tried this using 2 asp.net Radiobuttonlists controls on the same page. Got around the nasty bug with GroupName (asp.net assigns the control's uniqueID which prevents the groupname from ever working because now, 2 radiobuttonlists can't have the same groupname for all their radiobuttons because each radiobuttonlist has a different uniqueID thus the bug assigns the unique ID as the name attribute when the buttons are rendered. since the name sets are different, they are not mutually exclusive). Anyway, so I created that custom RadioButtonListcontrol and fixed that groupname problem.
But when ended up happening is when I went to put 2 instances of my new custom radiobuttonlist control on my .aspx page, all was swell until I noticed that every time I checked for radiobuttonlist1.SelectedValue or radiobuttonlist2.SelectedValue (did not matter which I was checking) the value always spit back string.empty and i was not able to figure out why (see http://forums.asp.net/t/1401117.aspx).
Ok onto the third try tonight and into the break of dawn (no sleep). I tried to instead just scrap trying to use 2 custom radiobuttonlists altogether because of that string.empty issue and try to spit out 2 sets of radiobuttonlists via using 2 asp.net repeaters and a standard input HTML tag inside. Got that working. Ok but the 2 lists still are not mutually exclusive. I can select a value in the first set of radiobuttons from repeater1 and same goes for repeater2. I cannot for the life of me get the "sets" to be mutually exclusive sets of radiobuttons.
As you have two groups of radio buttons that you want to function as one group of radio buttons, the solution is simple: Make it one group of radio buttons.
The only problem you have then is that the value that you get has the same name from both lists, but that can be solved by adding a prefix to the values so that you easily identify from which list the option comes.
Update: based on the new info posted as an answer. The option I proposed on my original answer corresponds to the 3. You really must consider the following:
Html radio buttons have only 1
built-in mechanism to handle the
exclusivity, which is the name.
You are explicitly requesting a no js solution, so given the above you must manipulate the Ids to achieve it. If you weren't blocking this option I am sure someone would come up with some nice jquery or js library that already supports it.
The option 3 is clearly the less invasive, as you are not forced to affect the actual data, and are not affected by future updates to it.
It's not that much code, just something extra on the List indexes, and some simple thing as:
int? list1Value = null;
int? list2Value = null;
var value = Request.Form["somegroup"];
if (value.StartsWith("List1"))
list1Value = int.Parse(value.Substring(5));
else
list2Value = int.Parse(value.Substring(5));//Assuming List2 as prefix
Original:
I saw your other question, and you just need to use the same group name. Make sure you have different values for all items regardless of the list they come from. A way to achieve this is adding something to the values, like: <%# "List1-" + Eval("ID") %> and modifying the code that reads your Request.Form["yourgroupname"].
I think you should just use RadioButtons instead of RadioButtonLists.
Here's an article that presents a solution to resolve the radiobutton naming bug.
Though this post is dated 1 year ago already, I just read it because I face the same problem.
Currently I have 1 solution using jQuery:
Client side script (you must also include jQuery)
function SetRadio(rb) {
$('input:checked').attr('checked', false);
rb.checked = true;
}
For every radiobutton (which is a listitem in a radiobuttonlist) I add the following on the serverside:
li.Attributes.Add("onclick", "javascript:SetRadio(this)");
For me this works in both IE and Firefox, with 3 radiobuttonlists, without using groupnames.
You can check each radiobuttonlist for a selecteditem/value, or you can extend the SetRadio function so it stores the selected value in a hidden field.
Regards,
M

Resources