-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for locating elements By XPath #31
Comments
There are no concrete plans on implementing XPath support in mobile drivers at the moment. You can take a look at notes in 2gis/Winium.Mobile#29 and try implementing it yourself. One of the reasons we have not implemented it yet is the fact that System.Xml.XPath was not available in Silverlight or Store Apps and one would had to use some third party repackaging of this assembly for targeted platforms. In our usage of the driver we were able to use mostly Id and Name strategies, and rarely ClassName strategies. Seems that XPath strategy is need in rare cases in complex UI or when there are no Id or Names specified in the elements, which might lead to the problem of tests breaking too often due to minor changes to UI structure. |
Yes , we are encountering 'breaks' in our tests due to sudden changes in UI tree of the AUT for web and mobile apps. We constantly have to update the locators depending on the changes if that happens, Thanks for the link, I'll investigate on what we can do with this 'cause most of our locators are in XPath |
May I know if you have tested codeduitestproject on Hybrid windows phone applications using Webview? |
It was not tested extensively. I am not sure if I have run any scenarios against any complex hybrid app. If I remember correctly I've run a scenario against single view app that had some native buttons and a single WebView. I've run scenario against preinstalled web browser in the emulator. WebViews are accessible by CodedUI and the driver (as it uses CodedUI), but it will not be how it works in Appium on Android or iOS, where you basically have two different contexts, one of which is web context that works like regular web page testing using selenium on desktop. If you have hybrid app, you can run an dummy test that prints out page source using PageSource command. All elements that you can see in outputted page source will be accessible by driver using |
So if I understood correctly, we cannot access html tags in the webview in the hybrid app (which is the reason why xpath doesn't and will not work) because the automation tree when using codedui in the app is different from the html tree when opening in browser? Also how do I create a dummy PageSource command? Is it similar to how we retrieve the page source using selenium webdriver? I am currntly away from my machine so I can't test our PageSource command for webdriver yet |
Do you think it's possible to parse xpath locators to its equivalent codedui "strategy" and "value" ? |
You can not access html tags in a way you do with selenium, they will be accessible like other native UI elements and will have the same set of properties like id, name and class, which are mapped form html tag attributes by CodedUI. By dummy page source test I meant an empty test case that simple prints page source of the screen you are interested in without any assertions. Something like class Test(unittest.TestCase):
desired_capabilities = {
'deviceName': 'Emulator',
'app': 'aut.appx'
}
def setUp(self):
self.driver = webdriver.Remote(
command_executor='http://localhost:9999',
desired_capabilities=self.desired_capabilities)
def tearDown(self):
self.driver.quit()
def test_page_source(self):
# assuming you want a page source of the first screen in the app
# if not, you can simple add break point in test, manually navigate to the screen
# that has WebView and release the break point
source = self.driver.page_source
print(source) XPath can be converted into combination of basic strategies and some code. For example, if you used XPath to find element with id="Submit" that is nested into element with Id="LogInForm", then you could use:
More complex cases might require getting all elements by some id, name or class and iterating them. |
It should, but I would recommend you to check this one using page source. I had some problems with a few elements on google page and, unfortunately, I do not remember details. I think I was able to locate elements using |
Hi, Searching for an element by xpath throws unknown strategy in By constructor.
will there be support for xpath locators?
The text was updated successfully, but these errors were encountered: