2gis / Winium.Mobile

Winium.Mobile is Selenium Remote WebDriver implementation for automated testing of Windows StoreApps and Silverlight apps, tested on emulators (currently only Windows Phone/Mobile apps are supported).
Mozilla Public License 2.0
51 stars 29 forks source link

How to use Xname Stratergy to find elements? #156

Closed Pranodayd closed 7 years ago

Pranodayd commented 8 years ago

Hi @NickAb . How can I use Xname element finding stratergy?Can I use xname as an attribute in Xpath? I tried using xname in xpath but didn't work. My xpath looks like this: //*[@class_name='' and @xname='']

Please help

NickAb commented 8 years ago

XPath locators are not supported yet. Use of x:Name depends on the language you use to write tests.

For example in python one can simple do

from selenium.webdriver.common.by import By

By.XNAME = 'xname'

But in C# standard locators can not be extended that way, so one would something similar to implementation in https://github.com/2gis/Winium.StoreApps/blob/master/Winium/TestApp.Test/Samples/WpDriver.cs#L67

Pranodayd commented 8 years ago

@NickAb I am using java.How can I use Xname locator strategy in Java?

NickAb commented 8 years ago

I do not know for sure, but this https://mguillem.wordpress.com/2011/10/06/webdriver-subclass-the-by-class-to-define-own-locators/ might help

Pranodayd commented 8 years ago

Hi @NickAb Can I get value of Xname property using getAttribute() function?

NickAb commented 8 years ago

Yes, it should be exposed as xname attribute

Pranodayd commented 8 years ago

Ok.Thanks.I will try using this technique then.

Pranodayd commented 8 years ago

@NickAb getAttribute("xname"); returning me a null. Why?Any idea?

NickAb commented 8 years ago

@Pranodayd, sorry, I misread your question. What I meant is that x:Name set in XAML can be obtained as a value of xname attribute of XML element when using pageSource command.


Here is the answer to you original question: When using getAttribute command x:Name might be accessed using Name property, e.g.

element.getAttribute("Name")

Note that accessing Name property would require at least DependencyProperties access level set in commandSettings.elementAttributeSettings.accessModifier capability, it won't be accessible if AutomationProperties level is explicitly set. You should be all set by default if you have not specified this capability at all.

NickAb commented 8 years ago

@Pranodayd where you able to find elements by x:Name?

Pranodayd commented 8 years ago

@NickAb Yes I could locate the element by x:Name.Thanks