Page-object - How to select an item from a select_list with dynamic values using item index - watir-webdriver

I have a select_list that gets populated in runtime. I need to select a value based on the item index.
Eg.
self.myselectlist1.option(indexval).select
If the indexval I pass is 3, it should select the third item.
The above code errors out. Is there an alternate way?

Assuming that myselectlist1 is the name of a select list defined in an accessor, you want:
self.myselectlist1_element.options[0].click
Explanation:
myselectlist1_element is used to get the select list element.
options returns an array of option elements for the select list.
[0] returns the first item of the options array
click clicks the option to select it. There is no select defined for options (ie you will get a deprecation warning).

You have 3 issues:
The method you're looking for is "options" not "option"
Use brackets instead of parenthesis.
use click instead of select.
myselectlist1.options[indexval].click

Related

How to use Parameter field in a record selection "like" statement?

I have designed a report to pull data fields based on a record selection formula that uses a "like" operator that looks for a substring match in a particular field's data, as so:
{rct.serno} like "*9842*"
(due to the free-format way data is stored in the given field, I have to do a substring match to find the relevant rows in the DB.)
This works fine. Instead of manually editing the record selection formula every time, though, I thought to use a Parameter field ("{?TagNum}") to prompt the user for the desired string, and then use that in the record selection formula like:
{rct.serno} like "*{?TagNum}*"
Crystal does not throw an error when I save this record selection formula, but it does not return any records after the report is refreshed, and a parameter value is entered. How can I properly use the parameter value in a record selection substring match?
You're really close to the solution. You can modify the formula in the Select Expert. Just click the Select Expert icon (or from the Report menu). Then click the Formula Editor button. Concatenate or add an asterisk onto the beginning and end of the parameter using the + operator, like this:
{Customers.LastName} like "*" + {?pLastName} + "*"
Let me know if that helps.
~ Nathan

Symfony2 DOMCrawler - How to select second option of a select tag

I'm trying to select the second option in a <select> tag with the DOMCcrawler. First of all, I select the second form in the page:
$form = $DOMCrawler->filter('form')->eq(1)->filter('input[type=submit]')->form();
Then I could change each value of the form by:
$form['value'] = "new value";
but I don't have a fixed key for each value. Instead, I have a variable number. E.g. I could have something like:
$form[1234];
but also could be
$form[4321];
depending on other variables. So I need to change the form values without knowing the key values, but its position in the node <form>. E.g. something like $form->firstKey();
Also, I want to select the second option inside <select> tag, not a fixed value. Any ideas on how to achieve it?

Preselecting Options not working in web2py

I have looked at the documentation at http://www.web2py.com/books/default/chapter/29/05/the-views?search=OPTION%28 and I have looked at the previous question How to preselect options in SELECT helper in web2py, but my selects have not been working properly.
I make the select:
select = SELECT(_name = attr)
I populate it by appending options in a loop
...
option = OPTION(the_string, _value=str(row.id))
select.append(option)
...
I set the selected value for the select
select.value = str(selected_value)
But the select does not have anything pre-selected. In the html, the correct option is not marked 'selected'. What am I missing?
value is an argument of SELECT.__init__ -- it is not an attribute that can simply be set after the object is created. If you want to change the selected attribute of an option after it has been created, you can do:
select.element('option[value=%s]' %
str(selected_value))['_selected'] = str(selected_value)
Or just specify the selected option when creating the OPTION object:
OPTION(the_string, _value=row.id, _selected=True)

how to retrieve multiple properties of selected list object from struts2 select tag through list key?

I have a list of objects in struts2 select tag. i want to retrieve the selected list object, not just id or any property as none of them or unique property, is there any way to get whole object? my code goes as below i want to retrieve all the fields, name,id,date,cba, seq.. as none of them are unique fields, i can not just get the id, then get the other fields from database.
any help???
<s:select name="appls" list="applList" id="appls"
listKey="id"
listValue="%{enroller.name.fullName + '-' + enroller.cba+'......' + openDateStr + '.....' + seq}"
multiple="true" />
What do you mean, "get the whole object" or "retrieve the list object"?
In any case, IMO you should build complicated option labels in Java, not in the view.
listValue can be an arbitrary OGNL expression, using the same value stack as the page itself, plus each of the select's list items pushed onto the top. Without knowing more about what you're actually trying to do, it's difficult to help much beyond that.

Why following XPath statement returns all "a" elements?

print $tree->findvalue('//a[1]');
I am using HTML::TreeBuilder::XPath in perl. Now i expect the above statment to return the value of second "a" element but instead it returns the value of all "a" elements in the page. I cant understand Why?
what you have shall return first a-child of every element.
so //a[1] will work as follows (result will be 2 nodes):
X
Y
a <-- give you this
a
Z
a <-- and this
a
try (//a)[1] instead
That XPATH expression looks for all a elements at every level of the document and the predicate filter selects the first a at every step.
So, depending on how your XML is structured, you might not get every a element (if there were more than one a that were siblings, you would only get the first one of those siblings).
However, if you intended to just select the first a in the document, you could use this expression: (//a)[1]
Wrapping the selection of //a in the parenthesis creates a collection that the predicate filter is then applied, selecting the first in the collection, rather than the first a encountered at each step of the //.