what to do when the resource-id of two elements in list view in UIAutomator of appium is same??
here in the images below:-
both the elements have same resource id:-net.one97.paytm:id/smart_list_root
Get the text using xpath:
String text = driver.findElement(By.xpath("//android.widget.RelativeLayout")).getText();
Compare the text and select the correct UIElement to perform desired action.
if(text.equals("Mobile Prepaid")){
......
}
Take it with multiple elements for xpath for textview as
"//android.widget.TextView[#text='Mobile Prepaid']"
Hope it will work
In this case, you can use xpath or name like below:
Way 1:
driver.findElement(By.xpath("//android.widget.TextView[#text='Mobile Prepaid']"));
driver.findElement(By.xpath("//android.widget.TextView[#text='Mobile Postpaid']"));
Way 2:
driver.findElement(By.name("Mobile Prepaid"));
driver.findElement(By.name("Mobile Postpaid"));
You can use By.name like,
driver.findElement(By.name("Mobile Prepaid"));
driver.findElement(By.name("Mobile Postpaid"));
String ac = driver.findElement(By.xpath("(//*[#resource-id = 'account-balance-amount'])[1]")).getText();
String ac = driver.findElement(By.xpath("(//*[#resource-id = 'account-balance-amount'])[2]")).getText();
Related
I have an array of view model. Now I want to check that view model array to contain a word within an array.
public IQueryable<CategorisedPostViewModel> GetRelatedPostbyCategories(string categories)
{
var ctries = categories.Split(',');
var result = GetAllCategoriedPost().**Where(p=>p.CategoryName.Contains(ctries)).**OrderByDescending(c => c.Published);
return result;
}
How can I search that bold portions without loop?
We may assume for simplicity,
p.categoryName="jerry,tom,ema"
and
ctries={"Gates","jerry","Jobs","ema"}
I want to check if any ctries is found on p.categoryName. Please help me. Thanks in advance.
To check if any category name is present in ctries try, Intersect
p.categoryName.Intersect(tries).Any()
I am relatively new to swift; I am working on filtering arrays.
I know how to filter out elements of an array that contain a letter (like so: let filteredList = wordlist.filter { !$0.characters.contains(letter) }), but how do I filter out elements that do not have a letter?
Here's what I want to accomplish:
I have a word list in string-array format, i.e. ["thing", "other thing"] (but much longer), and I want to return every element that has a certain letter, filtering out the ones that do not have a certain letter.
Thanks in advance.
This was a silly question, I am sorry. Anyway, I just needed to remove the exclamation mark. So...
let filteredList = wordlist.filter { !$0.characters.contains(letter) }
// returns elements in the array WITHOUT "letter".
let filteredList = wordlist.filter { $0.characters.contains(letter) }
// returns elements in the array WITH "letter".
Thanks Eendje.
My first time around here with a Swift related question with the SQLite.Swift library.
I have a for loop for a db.prepare statement, but I am stuck when trying to assign an array value to a UILabel.
// Prepare query to retrieve the message
var _phraseMessage:String = ""
let _stmt = _db.prepare("SELECT id, message FROM messages WHERE language = 'EN' AND category = 1 and username = 'user' LIMIT 1")
for row in _stmt {
println("id: \(row[0]), message: \(row[1])")
self._phraseMessageLabel = row[1] --> i get an error here **"'Binding' is not convertible to UILabel"**
}
How can assign the value in row[1] to my UILabel? Or even better to a String variable if possible.
Thanks in advance!
Disclaimer: This is my first attempt to Swift + Third party library
You're trying to set the UILabel property itself to your value - you want to set the text property on the label to your value:
self._phraseMessageLabel.text = row[1] as! String
If you want to assign the value to a variable:
var message = row[1] as! String
One thing to note is that with both approaches, your label text or variable will only end up being set to the value for the last row returned, the one that is processed last by the for loop.
Beyond Undo's fix above, I wanted to offer a couple other solutions.
Try using Database.scalar or Statement.scalar if you're only using a single value, as in your example above.
// make sure to remove "id" from your SELECT statement
self._phraseMessageLabel.text = _stmt.scalar() as! String
Note: Make sure to remove id from your SELECT statement; scalar returns the first column of the first row only.
Use the Statement.row cursor.
_stmt.step()
self._phraseMessageLabel.text = _stmt.row[1]
So, I have a cell with one label inside. I am trying to populate that label text with the various items in my array - all strings.
My array
var restauranttypelist: [String] = ["American", "Asian", "Bakery & Deli",
"Burgers", "Italian", "Mexican", "Seafood", "Steakhouse"]
and my cell label text
let type = restauranttypelist [indexPath.row]
var typecell = tableView.dequeueReusableCellWithIdentifier("cellone") as RestaurantTypeCell
typecell.restaurantTypeLabel.text = restauranttypelist.text
return typecell
I have tried a number of solution ranging from ".text" seen above, to ".String", to "restauranttypelist:indexPath.row" to no avail.
I suppose I have two questions. Am I setting up my array correctly? Do I need to insert the "[String]" portion after the variable name?
Finally, how would I be able to set the cell label to the numerous items I have in my array?
Thanks for any help... beginning.
Jon
In let type = restauranttypelist[indexPath.row] you're accessing a String from your Array and storing it in type. Therefore, all you need is typecell.restaurantTypeLabel.text = type.
There's nothing wrong with how you setup the array. You don't need the [String] type annotation since it can be inferred from the value you are assigning to it, but having it there does no harm.
Finally, this doesn't affect how your code works, but it's nice to know anyway:
Swift variable names follow the convention of starting with a lowercase character, and then capitalizing every subsequent word. Following that convention your variable names should be typeCell and restaurantTypeList.
I want my label to read like this:
Name of Activity
nn%
Instead, here's what appears:
%#
%f%
In addition, I'm getting this warning: Expression result unused
Here's the code I'm trying:
firstLabel.text = #"%#\n%#%",[self.thisSpec activityOfInterest],focusActivityPercent;
[self.thisSpec activityOfInterest] returns a string containing the name of an activity, and focusActivityPercent is a double.
This is the first time I've tried a multiline label.
Any suggestions?
Thanks
You can't specify string formatting on a string literal on its own like that. In fact, the code you've shown should be producing a syntax error. You have to use NSString's stringWithFormat: class method:
firstLabel.text = [NSString stringWithFormat:#"%#\n%#%",[self.thisSpec activityOfInterest],focusActivityPercent];