Get element by repeater with specific value in Protractor? - angularjs

Can I filter by.repeater('object in array') so it returns just objects with a specific value in Protractor?
E.g. something like
var filteredElements = element.all(by.repeater('object in array')).column('object.type').value('car'));
Is something like this possible without creating additional loops (and without creating new promises)?

These elements doesn't have any unique identifier? If they have you can do a cssSelector searching for that specific identifier (id, class or any other attributes..)
If they don't have ny unique identifier, the best way to do that is change you FE application to add the class "car" to each element that you want to have, and then, have a selector that retrieves all the element with class "car".

Related

How to fill form fields having same class

I am testing a website form using clj-webdriver. I want to know how to use (input-text) function if the form fields have same class.
From the (input-text) definition it gives "Type the string s into the first form element found with query q". Since every field has same class and when I give,
(input-text ".class")
It only fills the first field. Is there any way to differentiate all fields with the same class?
The fields of the form has only class and type as selectors.
Thank you
input-text only fills the first match.
Use quick-fill to fill them all.
E.g.,:
(quick-fill {".class" "s"})
/edit
You say "for 2 fields of same class I have to enter 2 and 3 as values. and also if the class is "object object-done" can I consider class as ".object". I am not exactly sure what you mean with the latter, but what I understand is that you want to add different values to different elements.
If you want to find specific elements you can use find-elements. These will return a collection of elements:
(find-elements {:class ".class"})
This will find all elements with the class ".class" in order which they appear on the page.
If the collection is stored in a variable text can be added to every element via input-text based on index. So for example if you want to add an increasing index to them you can use map-indexed to add the index of every value to the element as follows (doall is called to walk every element in the lazy sequence - function calls are only made when the elements are accessed and doall makes that happen):
(defn fill!
"Fills all elements with class class with increasing numbers."
[class]
(let [elements (find-elements {:class class})]
(doall
(map-indexed (fn [index element]
(input-text element (str index)))
elements))))
This function is called like (fill! ".class").
Hope this helps.
You should use the (find-elements [webelement by]) function, which returns a list of 'webelementsmatching a givenby`.
From the project documentation, that can be found at https://github.com/semperos/clj-webdriver/wiki/Introduction%3A-Taxi , an example is:
(defn css-finder
"Given a CSS query `q`, return a lazy seq of the elements found by calling `find-elements` with `by-css`. If `q` is an `Element`, it is returned unchanged."
[q]
(if (element? q)
q
(core/find-elements *driver* {:css q})))

How to search an element by its name in a web page using selenium webdriver

I am creating groups randomly. Then i need to check whether that group has been created or not. is there any way to search the group by its given name.
or element in a webpage by its name. i am trying it by using By.name locator, but not able to do that.
I just want to get an element in webpage by its name which is given by me/user.
For Ex: i have created a group "gr907", So how i can search or verify whether group having name "gr907" has been created or not.
Kindly Suggest
Given the example element you gave in the comment for your initial post - <span class="grpName">Gr9006</span> - and assuming that other relevant elements share the same class attribute, you could use the following example to retrieve a list of suitable WebElements:
List<WebElement> elements = driver.findElements(By.className("grpName"));
If this doesn't work, then your next course of action could be to make an XPath expression that identifies span tags whose inner text starts with "Gr", such as:
List<WebElement> elements = driver.findElements(By.xpath("//span[contains(text(),'gr')]"));
To find a single element containing the group name created at run time as its exact text content, you can simply pass it in to an XPath like so;
WebElement element = driver.findElement(By.xpath("//span[.='" + group name + "']");

applying class in ng-repeat if contained in another array

I am querying for a collection of IDs from Parse.com and showing them in my $scope as an array.
I would like to apply a class to the items in my $scope that match any one of these IDs, placing a border around the object illustrating that it is already contained in the 'saved' array. I have tried the following however not having any luck.
ng-class="{'approved': ParseSavedExercises.indexOf(exercise.id) == -1}"
in this case my ParseSavedExercisesis my array to check against and exercise.id is what I am checking for.
here is a quick fiddle
Please see here http://jsfiddle.net/e9pr4yqj/
Yours ParseSavedExercises contains string and id is number so no id existed in ParseSavedExercises
$scope.ParseSavedExercises = ['2','3'];
change to
$scope.ParseSavedExercises = [2,3];
or use
ng-class="{'approved': ParseSavedExercises.indexOf(exercise.id.toString()) == -1}"
like here http://jsfiddle.net/1ujgvL80/

How to find entries which has not empty StringListProperty?

I have a following model in the Google appengine app.
class TestModel(db.Model):
names = db.StringListProperty(required=False)
So, I want to get entries which has not empty in names property. I tried like this.
TestModel.all().filter('names !=', [])
But it raises the exception: BadValueError: Filtering on lists is not supported
How can I filter it? or Should I check one by one like following?
for entry in TestModel.all():
if len(entry.names) > 0:
result.append(entry)
Try this:
TestModel.all().filter('names >=', None)
This will give you every entity with at least one value set for names, i.e. every value in the index.

gqlquery for no values in ListProperty

I have this code to find all the nodes where property branches is empty.
nobranches=TreeNode.all()
for tree in nobranches:
if tree.branches==[]:
I wanted to find a better, more efficient way to do this. A meathod where I don't have to retrieve all the TreeNodes. I have tried TreeNode.all().filter(branches=[]) but this gives me a message, "BadValueError('Filtering on lists is not supported'" . How can I do something like TreeNode.gql('WHERE branches=:1', []).fetch(100). I tried this, but I get a "BadValueError: May not use the empty list as a property value; property is []". Is there any other efficient way?
BTW, Here is what TreeNode looks Like
class TreeNode(db.Model):
name = db.StringProperty()
branches =db.ListProperty(db.Key)
You can't do this with a filter: as Saxon says, there's no index row matching what you want to retrieve, and so no way to retrieve it.
One simple alternative is to store another property that contains the number of elements in the list, and filter on that. aetycoon is a library that contains computed properties that may help with that:
class TreeNode(db.Model):
name = db.StringProperty()
branches = db.ListProperty(db.Key)
branch_count = aetycoon.DerivedProperty(lambda self: len(self.branches))
The documentation on how indexes are stored says:
For multi-valued properties, such as ListProperty and StringListProperty, each value has its own index row, so using multi-valued properties does result in more indexing overhead.
So for each item in your list property, there is a row in the index.
My expectation would be that if there are no items in the list property, then there would be no rows in the index. So it wouldn't be possible to use the index to retrieve entities with an empty list.
One solution would be to add another property (eg hasbranches = db.BooleanProperty()), which you maintain when you add or remove branches. Then you will be able to filter for hasbranches = False.

Resources