Objective: To click on Access for all guest users.
I am unable to find this element.
uiautomatorviewer shows the following screenshot.
Content description is following copy/pasted
"Access for all guest users
Provider not listed? Stay tuned, we will be adding more TV providers shortly."
Notice: the line break after user. I believe this is why my xpath is not working.
My xpath is:
"//android.view.View[#content-desc ='Access for all guest usersProvider not listed? Stay tuned, we will be adding more TV providers shortly.']"
I cannot use index instead of content-desc because of the object in layers above have the same class and index.
Using tap to a specific might solve the problem but is not a good solution.
any ideas on how to handle that linebreak.
If you notice the XML hierarchy, you will notice that your element is inside a WebView (3rd node from top). So its not getting identified. You have to first switch to WebView and then use your code.
The way you mentioned the xpath should work, once you switch to WebView.
Related
This is with Robot Framework running with Appium version 1.5.04 on an Android physical device with the device context set to NATIVE_APP
Steps to reproduce: using an xpath relationship where the element we want (a button) is a child of a View where there are multiple Views entities at the same level
The derived xpath: xpath= //[#class='android.widget.Button' and ./parent::[(./preceding-sibling::* | ./following-sibling::*)[contains(#contentDescription,'Sticky')]]]
This xpath is intended to act on a Button that is a child of a View element that contains the name 'Sticky'
What I'm finding is that the following Click Element keyword works fine (both finds and clicks the element)
e.g.:
Wait Until Keyword Succeeds 5x 3 sec Click Element xpath= //*[#class='android.widget.Button' and ./parent::*[(./preceding-sibling::* | ./following-sibling::*)[contains(#contentDescription,'Sticky')]]]
However, any of the conditional keywords, e.g.: (I don't always want to click the element, just see if its there or not there)
Element Should Be Visible xpath= //*[#class='android.widget.Button' and ./parent::*[(./preceding-sibling::* | ./following-sibling::*)[contains(#contentDescription,'Sticky')]]]
(same xpath used)
Gives an error: ValueError: Element locator with prefix '//*[#class' is not supported
I've tried other element values (e.g. ContentDescription) with the same result. This particular element unfortunately does not have an assigned id.
Is there different xpath syntax that I should be using or a different keyword that would be better suited?
I'm not sure why there is a discrepancy between the two, but I'm guessing the fix is to use : rather than = to separate the prefix from the locator:
Element Should Be Visible xpath://*[#class='android.widget.Button'...
Both robot and the selenium library use = to help identify a keyword argument (robot) or locator prefix (selenium). That problem can be avoided by using : for the prefix.
I am new for automation testing.
I am trying to automate UI and want to tap on humburger menu.
I tried it with
1. MobileElement el1 = driver.findElement(By.xpath("//*[#content-desc='" + "Menu" + "']"));
el1.click();
2. MobileElement el1 = driver.findElement(By.name("Menu)"));
el1.click();
3. MobileElement el1 = (MobileElement) driver.findElementByXPath("//android.widget.ImageButton[#content-desc=\"Menu\"]");
in all the cases i got error for element not found.
But when i tap manually on menu within test befor el1.click() get executed then test get run successfully. It is just like menu element get focused and appium find it.
So how to execute this without tap or getting focus?
Try to find the element by its name. In UI Inspector search before with name or any other locator. If it searches successfully with few attempts. Sometimes element has dynamic identification.
Can you try your code again but this time set the capability automationName to uiautomator2? Your problem sounds like the ones I have sometimes and moving from UIA1 to UIA2 (uiautomator2) solved that. UIA2 is however a bit more slow detecting elements IMO.
I'm new to automatization, Android, Selenium, Appium and xpath, too. I know it's suck a great beggining.
I write tests for Android devices, but the application I have to test have a lot of costum views. I found out the best way to interact with these custom items is to put an "android:contentDescription" field in the Views. My only question is how to get access to the element with have a specified contentDescription? This is az android specific question, I'm not even sure that the content-desc is the field I'm looking for.
I have the hierarchy provided by Android UI Animator Viewer:
http://i.imgur.com/NUGc56o.png
The ways i've tried:
xpath: //*[contains(#android:contentDescription,'example text')]
I was able to get access by finding them as an ImageView, but as I mentioned I need to work with custom Views
My code looks like somtihng like this:
driver.findElementByXPath("//*[constains(#content-desc,'Login')]").click();
Thanks for the help!
You could also try using Accessibility labels or the UIAutomator locator strategy.
Here's Appium's documentation on those.
Your xpath is incorrect. It should be: "//android.widget.ImageView[#content-desc='Login']"
Here's some pseudocode of what you should do:
login_image = driver.findElementByXPath("//android.widget.ImageView[#content-desc='Login']"); // Gets you the WebElement
print login_image.getClass(); // Just for debugging, make sure it's not nil/null
login_image.click(); // Click on it!
When running calabash-android and outputting to HTML format, I am getting intermittent exceptions as per the below (typically within the first step of the app). I am using Xamarin and MVVMCross libraries.
Timeout waiting for elements: * marked:'Terms of Use'
(Calabash::Android::WaitHelpers::WaitError)
./features/step_definitions/calabash_steps.rb:4:in `/^User has accepted the Terms of Use$/'
features\registration.feature:8:in `Given User has accepted the Terms of Use'
2
3Given /^User has accepted the Terms of Use$/ do
4 #current_page=page(TermsOfUse).await
5 #current_page.tap_accept_button
6end
7# gem install syntax to get syntax highlighting
The screenshots generated show the UI element is present on the screen, and the same errors never occur when I exclude the html format option and simply write the detail out to the console. Does anybody else have any experience of this?
Most likely the view's text has some formatting information in it.
It's a good practice to use id instead of text for identifying elements. If you have an id, use that:
query("* id:'terms_of_use_id'")
If you don't have an id try to add one.
If that is not possible try to query the whole UI with:
query("*")
Find the element and see what's in it's text property.
I am doing direct queries to wikipedia's website via an android app.
However, sometimes when I get "REDIRECT" queries, and my redirect suggestion has a # sign in it, I don't really know how to handle it. I know I can just throw everything out past the # sign, but that means I'm looking up something that is relatively unimportant.
Here is an example link;
http://en.wikipedia.org/w/api.php?action=query&prop=extracts&titles=Poof_(The_Fairly_OddParents)&format=json
I can just redirect to List_of_The_Fairly_OddParents_characters, but I want to know if there is anything useful I can do with the "#Poof" because I'm sure that the information is there for a reason.
I could not find anything on MediaWiki APIs.
Please help!
Thanks
Most of the time the part after the hash is a section title (though it is simply appended to the new URL, so it can be, and occasionally is, used to point to other kinds of anchors), so you can locate the section (with the mobileview action for example) and with the section index you can query the HTML for that section. (extracts does not support sections, so you you must use something else and enforce length limits manually.)
The hash points to a named anchor or ID in the target document. So if you're parsing the page content, then ideally you'd find the anchor tag or ID and return the content that follows that element, rather than starting at the beginning of the content.