Get element Id from a found element - coded-ui-tests

I'm using the Chrome driver and Selenium tools in my CodedUI tests. I can find the element I need using the SearchProperties and a Contains operator however I need the full Id for subsequent searches.
For example I need to find an input element with Id "pm_modal_28".
This is easy enough by doing a search where Id contains "pm_modal".
I then need to parse the value "28" out of the Id that was found so I can search for the next nested element which has an Id of "dp_28".
When I use the Id property of HtmlDiv I get a NotSupportedException. Is there anyway I can get all of the Html attributes from an Element or get the Id from an element after it has been found?

Not sure if this what you are after, once the control is identified, you would have all its properties to play around with.
For example
var control = new HtmlDiv ();
control.SearchProperties.Add("Id", "MyDiv_28");
if (!control.TryFind()) return;
var newControl = new HtmlDiv();
newControl.SearchProperties.Add("Id", control.Id.Split('_')[1]);
newControl.TryFind();

HtmlDiv myDiv = new HtmlDiv(browser);
//Add the search logic u want !
myDiv.SearchProperties.Add("class", "ClassName");
string onewayforID = myDiv.Id;
string anotherWay = myDiv.GetProperty(HtmlDiv.PropertyNames.Id).ToString(); // Or u can simpy pass "Id"
See if that Works !

Related

Is it possible to find an element by the role attribute in protractor?

As I say in the title, is it possible to find an element by the role attribute in protractor? The attribute is as follows:
role = "menuitem"
I don't know if this item can be found by its attribute
Yes, you can. Here are examples of that:
$('[role = "menuitem"]'); // get one element
$$('[role = "menuitem"]'); // get list of the elements
element(by.css('[role = "menuitem"]')); // get one element
element.all(by.css('[role = "menuitem"]')); // get list of the elements

Using composed xpath to locate an element and click on it

I am trying to retrieve a list of elements using XPATH and from this list I want to retrieve a child element based on classname and click it.
var rowList = XPATH1 + className;
var titleList = className + innerHTMLofChildElement;
for(var i = 0; i < titleList.length; i++) {
if(titleList[i][0] === title) {
browser.click(titleList[i][0]); //I don't know what to do inside the click function
}
}
I had a similar implementation perhaps to what you are trying to do, however my implementation is perhaps more complex due to using CSS selectors rather than XPath. I'm certain this is not optimized, and can most likely be improved upon.
This uses the methods elementIdText() and elementIdClick() from WebdriverIO to work with the "Text Values" of the Web JSON Elements and then click the intended Element after matching what you're looking for.
http://webdriver.io/api/protocol/elementIdText.html
http://webdriver.io/api/protocol/elementIdClick.html
Step 1 - Find all your potential elements you want to work with:
// Elements Query to return Elements matching Selector (titles) as JSON Web Elements.
// Also `browser.elements('<selector>')`
titles = browser.$$('<XPath or CSS selector>')
Step 2 - Cycle through the Elements stripping out the InnerHTML or Text Values and pushing it into a separate Array:
// Create an Array of Titles
var titlesTextArray = [];
titles.forEach(function(elem) {
// Push all found element's Text values (titles) to the titlesTextArray
titlesTextArray.push(browser.elementIdText(elem.value.ELEMENT))
})
Step 3 - Cycle through the Array of Title Texts Values to find what you're looking for. Use elementIdClick() function to click your desired value:
//Loop through the titleTexts array looking for matching text to the desired title.
for (var i = 0; i < titleTextsArray.length; i++) {
if (titleTextsArray[i].value === title) {
// Found a match - Click the corresponding element that
// it belongs to that was found above in the Titles
browser.elementIdClick(titles[i].value.ELEMENT)
}
}
I wrapped all of this into a function in which i provided the intended Text (in your case a particular title) I wanted to search for. Hope this helps!
I don't know node.js, but in Java you should achieve your goal by:
titleList[i].findElementBy(By.className("classToFind"))
assuming titleList[i] is an element on list you want to get child elements from

Getting value of key from Web Content Display Portlet

I got a requirement. I have added two text fields Value and Key from structure in Web Content Display portlet.
right now in the portlet i am getting value from hard code like below.
BasicModel model = (BasicModel)requestContext.getFlowScope().get("BasicModel");
if(model == null){
model = new BasicModel();
}
model.setEmployeeId("AB1223344S");
model.setHireDate("01-Jan-2000");
model.setNiNumber("AB123456S");
model.setDateOfBirth("12-Dec-1980");
model.setBasicForm(new BasicDetailsForm());
}
but what i want is to get the value of each attribute from web content. Like, If i have given lfr.intel.empid as key and ABSD1822D as value in the added web content structure field like this.
and we can fetch the value of key like this.
model.setEmployeeId(lfr.intel.empid);
You can write a custom function for this which passes the key to that function, now that function will use the JournalArticleLocalServiceUtil API to get respective value from the DB.
Now you need to find How to fetch values from JournalArticleLocalServiceUtil, which you can google or this link can help you.
Thanks.
Try this, assuming that you could get the JournalArticle object, I've done it using the resourcePrimKey
long resourcePrimKey = 12345; //hard coded the resourcePrimKey
JournalArticle article = JournalArticleLocalServiceUtil.getLatestArticle(resourcePrimKey);
com.liferay.portal.kernel.xml.Document document = SAXReaderUtil.read(article.getContentByLocale("en_US"));
Node keyNode = document.selectSingleNode("/root/dynamic-element[#name='Key']/dynamic-content");
String key = keyNode.getStringValue();
Node valueNode = document.selectSingleNode("/root/dynamic-element[#name='Value']/dynamic-content");
String value = valueNode .getStringValue();

getDocumentByKey with a number vector doesn't find the document

I have a 2 column sorted view and try to get a document the following code:
var searchArr = new java.util.Vector();
searchArr.addElement(10000310);
searchArr.addElement(45);
var customerdoc:NotesDocument = viw.getDocumentByKey(searchArr,true);
but the result is null.
If I use only the first element for the key (10000310), then I get (the first) doc with that key. But with the 2-element-vector the lookup returns null.
the same in LotusScript works fine:
Dim searchkey(1) As Double
searchkey(0) = 10000307
searchkey(1) = 45
Set doc = luview.Getdocumentbykey(searchkey, true)
gives me the document I need.
Confusing, for me ....
Uwe
This is a known bug, hopefully to be fixed in 9.0.2. See this question getDocumentByKey with view category separated by "\\" in XPages
Your LS example uses an array, not a Vector. I am not even sure if it is intended to work with a Vector - never did that. So just use an array here, too, as the key.

Magento: getting attributes from an attribute set without a product

I have set an attribute set in my Magento shop which has several binary attributes.
For a pulldown I need a list of ALL the attributes inside this one attribute set, including their internal name and their label. Since this pulldown should appear in places that not necessarily have a product selected I can't go the usual route of "getting the attributes of a product".
How do I go about of getting a list of all the attributes inside my set?
OK, I realised that I missed that you want the whole set of attributes, not just an individual one. Try this:
$productEntityType = Mage::getModel('eav/entity_type')->loadByCode(Mage_Catalog_Model_Product::ENTITY);
$attributeSetCollection = Mage::getResourceModel('eav/entity_attribute_set_collection');
$attributesInfo = Mage::getResourceModel('eav/entity_attribute_collection')
->setEntityTypeFilter($productEntityType->getId()) //4 = product entities
->addSetInfo()
->getData();
You'll then need to iterate through the array that is returned with something like:
foreach($attributesInfo as $attribute):
$attribute = Mage::getModel('eav/entity_attribute')->load($attribute['attribute_id']);
echo 'label = '.$attribute->getFrontendLabel().'<br/>';
echo 'code = '.$attribute->getAttributeCode().'<br/><br/>';
endforeach;
Sorry for missing the original point, hope this helps!
Cheers,
JD
In order to get all the attributes in an attribute set, you can use as:
$entityTypeId = Mage::getModel('eav/entity')
                ->setType('catalog_product')
                ->getTypeId();
$attributeSetName   = 'Default'; //Edit with your required Attribute Set Name
$attributeSetId     = Mage::getModel('eav/entity_attribute_set')
                    ->getCollection()
                    ->setEntityTypeFilter($entityTypeId)
                    ->addFieldToFilter('attribute_set_name', $attributeSetName)
                    ->getFirstItem()
                    ->getAttributeSetId();
$attributes = Mage::getModel('catalog/product_attribute_api')->items($attributeSetId);
foreach($attributes as $_attribute){
    print_r($_attribute);
}
Cheers!!
try this snippet, it should give you want you need, except for multi-select attributes.
$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product','attribute_name');
foreach($attribute->getSource()->getAllOptions(true,true) as $option){
$attributeArray[$option['value']] = $option['label'];
}
return $attributeArray;
Hope this helps,
JD

Resources