espresso > how to select an option value in webview? - android

in webview ,
i got two dropdownlist element with same option value
at first dropdownlist, i could select an option value by
onWebView(Matchers.allOf(isDisplayed(), isJavascriptEnabled()))
.withElement(findElement(Locator.XPATH, "//option[#value='01']"))
.perform(webClick());
then, the result also action in first dropdownliast while i paste the same code
i though XPATH is search form head, so second dropdownlist won't work
anyone could help me how to select option value in second dropdownlist?

update my answer as below
i think i slove by myself, i add second parameter to check value, show as below
onWebView(Matchers.allOf(isDisplayed(), isJavascriptEnabled()))
.withElement(findElement(Locator.XPATH, "//dd[#class='visitorBirth']//option[#value='01']"))
.perform(webClick());

Related

How to replace/delete comments or lines starts with particular word in Android studio?

I want to delete all comments in an android project, all the comments start with // or any other specific characters?
Note: I'm answering myself I figure it out
In android studio, right-click on the project and select Replace in files, a new window pop up
1 in the first search field tape in this ^\s+//.*$
2 in the second search field, keep it empty if you just want to delete all the lines that start with //
3 now hit replace all button.
if you want to delete other lines that start with different characters, example # the expression should be like this ^\s+#.*$
to delete all the comments just use CTRL + r and write ^\s+//.*$ in first box
but make sure to check the box Regex
and in second write no thing and press replace all as shown below

Espresso : How to click on an item at position 2 in AdapterView

I am new to Espresso and Mobile Testing, and I am facing a challenge. I have to search for a contact in App and click on contact displayed at second position.
I checked many posts which were similar but however none of those worked for my example.
Code to Search : onView(withId(R.id.textSearch)).perform(typeText("pa"));
Code to Select : onView(withText("Parth Vyas")).perform(click());
But here if I want to select any element which is displayed at position 2, how can I do that?
If you know the position after search, then you can try something like:
onData(anything()).inAdapterView(YOUR_ADAPTER_VIEW_MATCHER).atPosition(2).perform(click());

Selecting an element on Appium / Android with Python that has same Class and Same Index of another element on UIAutomatorViewer

I am testing an app and on most of the screens I see that there are elements that have the same class "android.widget.TextView" with same index number "0". All other properties also same, only exceptions are the "text" and "bound".
I have "Skip", "Next" and "Skip Next 3" as texts on the screen which has the same attribute other than the text and bounds Attribute. I need to know how I can point appium to click on the desired item .. say I want to click on "Next", how can I do this. I am using Python for the scripting.
You can search for all matching web elements with the same class name, which will return you a list of the matching elements. Then you loop over the found elements and you compare their text, e.g :
for element in webdriver.find_elements_by_class_name('android.widget.TextView'):
if element.text == "Next":
element.click()
Doing as Chuk Ultima said will work, but if you have lots of TextView it may take a while.
You can use:
((AndroidDriver<MobileElement>)driver).findElementByAndroidUIAutomator("new UiSelector().text(\"Next\")");
See more usages in http://www.automationtestinghub.com/uiselector-android/
Well, In my case I finally solved the problem using traversing through nodes like I created xpath to get the Text (time value) from a particular location like this:
Time = self.driver.find_element_by_xpath('//android.widget.LinearLayout[#index=2]/android.view.ViewGroup[#index=0]/android.view.ViewGroup[#index=0]/android.view.ViewGroup[#index=0]/android.view.ViewGroup[#index=3]/android.view.ViewGroup[#index=0]/android.widget.TextView[#index=0]').get_attribute('text')
I understand this is a tedious process, but for the time being this is the solution for me.

Calabash android, as clicking a ListView?

I've been looking for the answer on the Internet, but could not find it. help me please.
How to make pressing the list item in Calabash-Android?
Try this out
Add a definition to ruby step file.
Then /^I scroll to cell with "([^\"]*)" label and touch it$/ do |name|
element="TextView text:'#{name}'"
if !element_exists(element)
wait_poll(:until_exists => "TextView text:'#{name}'", :timeout => WAIT_TIMEOUT) do
performAction('scroll_down')
end
if element_exists(element)
touch(element)
sleep(STEP_PAUSE)
else
screenshot_and_raise "could not find the cell"
end
else
touch(element)
sleep(STEP_PAUSE)
end
end
and call it from feature file Then I scroll to cell with "cellMainLabel" label and touch it
The answer above looks a bit more fool proof than mine but I have been using the following quite happily:
spinner selection
Then (/^I select spinner by id "(.*?)"$/) do |spinnerid|
touch("spinner id:'#{spinnerid}'")
end
select an item in the damn spinner
Then (/^I touch "(.*?)"$/) do |text|
touch("TextView text:'#{text}'")
end
it's two steps, first part will select the spinner via its id and then the second part selects the item in the spinner via the text you quoted.

logical problem in an android app

hi i would like to know solution for such a problem..... i have an xml file containing users data of around 1000 users listed out in alphabetical order. The xml file use to be as follow
<usersdata>
<user>
<id>1</id>
<firstname>A</firstname>
<middlename>AA</middlename>
......
......
</user>
<user>
<id>2</id>
<firstname>B</firstname>
<middlename>BB</middlename>
......
......
</user>
........
........
</usersdata>
Now from the above xml file i am parsing all the tags and storing them in an array list for each tag. I am listing out the Firstname in a listview, by array list of first name. When the any of the list is clicked, it opens up a new activity where the all other details of the selected name is been shown.
For example if third name in the list is clicked, by using its position(example 3), in the next activity i am listing out the third values stored in all the array lists i am using. This is what currently i am doing.
Now the problem is i have a edit box above the list view, named as a search box. If the letter S is typed in it, then all the names starting with S gets listed first. Opening the next activity by clicking the list now gets some wrong data, how to avoid this.
Please give me a suggestion....
For example if the first name C is clicked, it will be listed at position 3
There is a quick and dirty hack: you can store user id in the invisible field, retrieve it on click and use it as an argument for the second activity. I'm afraid I can't come up with better suggestions without seeing the code.
i tried out by setting some flag and by using an example code in developers site. And i am able to list out the data's but this idea does not full fill my apps requirement in the next activity. So i removed the search part in my app.
Sorry for posting such a question here......

Categories

Resources