How do I capture element embedded in nested Shadow-root? - shadow-root

I understand this might be a repeated question as I have seen some similar issues and solutions already provided. However, none of the tricks are working for me. Please if you can suggest how do I capture the highlight box in the below HTML - that would be helpful. Thanks in Advance.
HTML Code
IWebElement root = VU.Find(By.CssSelector("wc-doc"));
Pause(5000);
IWebElement Shadowroot1 = VU.getShadowRootElement(root);
Pause(5000);
IWebElement elem1 = Shadowroot1.FindElement(By.CssSelector("wc-spread"));
Pause(5000);
public IWebElement getShadowRootElement(IWebElement element)
{
IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
IWebElement temp = (IWebElement)(js.ExecuteScript("arguments[0].shadowRoot", element));
return temp;
}
The above method getShadowRootElement() is in a Library.

Related

How to use the widget fullpath to access widget's properties?

I know that using widget.getFullPath() method, we can retrieve the full path of a widget as a string in the format "pagename.child1name.child2name....childNname.widgetname".
I am trying to find a way for using this string to access the original widget.
I was successful using this:
app.pages["pagename"].children["child1name"].children["child2name"]....children["childNname"].children["widgetname"].text = "some text";
but I don't know how to change this in a more general function, independent by the depth of the path.
Any idea would be very much appreciated. Thank you.
The parent root descendents should have everything on the page, so try:
widget.parent.root.descendants.ANYTHING.value;
you might alternately need to do this if you want ANYTHING to be a variable
widget.parent.root.descendants[ANYTHING].value;
My intention is to access the widget's property from another page. The root of a widget is its page, and it is the string before the first dot in the full path.
I eventually wrote a function which builds the object after splitting the full path string in an array:
function getWidgetPath(pathString) {
var pathArray = pathString.split('.');
var widgetPath = app.pages[pathArray[0]];
for( i=1; i<pathArray.length; i++ ) {
widgetPath = widgetPath.children[pathArray[i]];
}
return widgetPath;
}
The function can be used to build the target object. I.e., considering that the target widget is a label and I want to change its text property, I use:
var targetPath = 'parentpage.panel1.panel2.panel3.label1';
var targetWidget = getWidgetPath(targetPath);
targetWidget.text = 'some text';
I have the feeling that it's not very Javascriptian, though.

Caliburn.Micro multiple element custom Conventions (NumericUpDown.Value,NumericUpDown.Maximum)

I've been messing around with CM conventions trying to understand how they work but i haven't found a decent article somewhere explaining step-by-step how and why.
However I've found a few code snippets that i've been working with with some success.
In this case, however, i don't understand what is going on.
I'm trying to bind a NumericUpDown Value and Maximum to a corresponding ViewModel property. I was able to do it with the following code:
Value
ConventionManager.AddElementConvention<NumericUpDown>(NumericUpDown.ValueProperty, "Value", "ValueChanged");
Maximum
ConventionManager.AddElementConvention<NumericUpDown>(NumericUpDown.MaximumProperty, "Maximum", "MaximumChanged");
var baseBindProperties = ViewModelBinder.BindProperties;
ViewModelBinder.BindProperties =
(frameWorkElements, viewModels) =>
{
foreach (var frameworkElement in frameWorkElements)
{
var propertyName = frameworkElement.Name + "Max";
var property = viewModels.GetPropertyCaseInsensitive(propertyName);
if (property != null)
{
var convention = ConventionManager.GetElementConvention(typeof(NumericUpDown));
ConventionManager.SetBindingWithoutBindingOverwrite(
viewModels,
propertyName,
property,
frameworkElement,
convention,
convention.GetBindableProperty(frameworkElement));
}
}
return baseBindProperties(frameWorkElements, viewModels);
};
However, an here comes the weird part, i can only make one of them to work. That makes me believe that i'm doing some noob mistake somewhere. It almost seems i can only call AddElementConvention and therefor only the last call is executed.
I would appreciate either a help with this piece of code or a reference to some good documentation that could help me with it.
Best Regards
i found out somewhere that CM only allows one convention per item so that's the reason of this behavior...
However since items like ComboBox allows binding for multiple properties (SelectedItem, ItemSource and so on...) i'm not completed convinced...

Getting characters position in TLF

i am trying to figure out if i can in anny way get the exact position for every character inside a textflow?, also I'm having trouble with the TLF documentation, is there anny documentation that shows more on how to work with it in actionscript rather than mxml, im looking to write my own component and perhaps not use richtexteditor if i don't need to.
Many thanks!
Edit: i finally think i figured out how to get each characters position in the textflow:
private function getCharPosition():void {
for (var i:int=0; i<=textController.flowComposer.numLines; i++) {
var textFlowLine:TextFlowLine = textController.flowComposer.findLineAtPosition(i);
var textLine:TextLine = textFlowLine.getTextLine();
trace('number of atoms in this line: ' + textline.atomCount);
for (var j:int=0; j<=textLine.atomCount; j++) {
try {
trace(textLine.getAtomBounds(j));
} catch (e:Error) {
trace('error');
}
}
}
}
This returns an error that's why i have try and cache, i have tried to change textLine.atomCount to -1 but that wont work either. Now i don't know what character exactly that i have the position for. Lots of figuring out yet...
You can use some of these steps which (among other things) allow to determine character's bounds.
What about your second question you can refer to the following documentation and/or some samples.

Flex 3: TypeError #2007 & Deeplinking

I'm getting Flex error #2007, right when the app starts up.
TypeError: Error #2007: Parameter child must be non-null.
at flash.display::DisplayObjectContainer/getChildIndex()
at mx.core::Container/getChildIndex()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\Container.as:2411]
at mx.containers::ViewStack/set selectedChild()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\containers\ViewStack.as:557]
at property/parseUrl()[/Users/myname/Documents/Flex Builder 3/property/src/property.mxml:8803]
at property/initBrowserManager()[/Users/myname/Documents/Flex Builder 3/property/src/property.mxml:8749]
at property/___property_Application1_creationComplete()[/Users/myname/Documents/Flex Builder 3/property/src/property.mxml:19]
I'm trying to get deeplinking to work properly. Bhasker Chari on the Adobe Flex forum was kind enough to help me with the code below:
private function parseUrl(e:BrowserChangeEvent = null):void {
var o:Object = URLUtil.stringToObject(browserManager.fragment);
var j:Object = o.view;
var f:String = String(j);
var c:String = f.replace(/-/g,"_");
var t:Container = mainViewStack.getChildByName(c) as Container;
mainViewStack.selectedChild = t;
}
Basically, I take the browserManager.fragment, convert it to a string, replace the dash with an underscore, convert it to a container, and use that to set the the selectedChild on the mainViewStack.
But, when it initializes, it says that there is no child parameter. How can I solve this problem?
Thank you.
-Laxmidi
Okay,
I figured it out. I need to add:
if(t!=null){mainViewStack.selectedChild = t}
else{mainViewStack.selectedIndex = 0}
The children hadn't been created, yet.
Thank you.
-Laxmidi

AS3: reading embedded metadata in flex

I saw that you can embed meta-data into images very much like you can in mp3s, here.
Can someone point me to a tutorial of how to embed and read this sort of information w/ photoshop and flex together?
I really wouldn't know where to start... Tried googling but I'm not sure I have the right keywords down.
Thanks!
I've written a small snippet on the matter. this snippet is far from being proper tested, and is most definite not written in a clear and coherent way. But for now it seems to work. I'll update as I work on it.
private function init(event:Event):void
{
var ldr:Loader = new Loader();
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, imgLoaded);
var s:String = "link/to/asset.jpg";
ldr.load(new URLRequest(s));
}
private function imgLoaded(e:Event):void{
var info:LoaderInfo = e.target as LoaderInfo;
var xmpXML:XML = getXMP(info.bytes);
//trace(xmpXML);
var meta:XMPMeta = new XMPMeta(xmpXML);
}
private function trim(s:String):String{
return s.replace( /^([\s|\t|\n]+)?(.*)([\s|\t|\n]+)?$/gm, "$2" );
}
private function getXMP(ba:ByteArray):XML{
var LP:ByteArray = new ByteArray();
var PACKET:ByteArray = new ByteArray();
var l:int;
ba.readBytes(LP, 2, 2);
/*
http://www.adobe.com/devnet/xmp.html
read part 3: Storage in Files.
that will explain the -2 -29 and other things you see here.
*/
l = LP.readInt() - 2 -29;
ba.readBytes(PACKET, 33, l);
var p:String = trim(""+PACKET);
var i:int = p.search('<x:xmpmeta xmlns:x="adobe:ns:meta/"');
/* Delete all in front of the XMP XML */
p = p.substr(i);
/*
For some reason this left some rubbish in front, so I'll hardcode it out for now
TODO clean up
*/
var ar:Array = p.split('<');
var s:String = "";
var q:int;
var j:int = ar.length;
for(q=1;q<j;q++){
s += '<'+ar[q];
}
i = s.search('</x:xmpmeta>');
i += ('</x:xmpmeta>').length;
s = s.slice(0,i);
/* Delete all behind the XMP XML */
return XML(s);
}
Originally from http://snipplr.com/view/51037/xmp-metadata-from-jpg/
Photoshop (CS4+ I think) can also add XMP headers (XML style) which will be easier to parse than bytes but it contains different information.
http://code.google.com/p/exif-as3/
Here is a class that should do the job. It is non-commercial only but there is another option.
www.ultrashock.com/forums/server-side/extracting-metadata-from-photos-86065.html
Here is a php script that will do it that could be ported to as3 - it might be easier than creating one from scratch. If you did want php to read the info I would use the built in exif functions :)
Well AS3 don't have a built-in class to read jpg header.
BUT, if you are loading the image using URLLoader you can use the ByteArray to read if manually.
You can find the spec here:
http://www.obrador.com/essentialjpeg/HeaderInfo.htm
If you need some tutorial of using Bytearray you can start from here:
How to convert bytearray to image or image to bytearray ?
or here:
http://digitalmedia.oreilly.com/pub/a/oreilly/digitalmedia/helpcenter/flex3cookbook/chapter8.html?page=7
The principle is the same -read the bytes, convert them to readable data using the spec above and use it.
Good luck!
Yes, entirely possible. ByteArray is your friend.
You may want to give a read to this:
http://www.anttikupila.com/flash/getting-jpg-dimensions-with-as3-without-loading-the-entire-file/
This may also be of use, but I'd rather go with the first option:
http://download.macromedia.com/pub/developer/xmp/sdk/XMPLibrary-v1.0.zip

Resources