How to find form submit input in Protractor - protractor

For fun/practice I write a test for Google advanced search and I am looking for a locator that will allow to find the form submit on https://www.google.com/advanced_search:
<input class="jfk-button jfk-button-action dUBGpe"
style="-webkit-user-select:none;user-select:none;line-height:100%;height:30px;min-width:120px"
value="Wyszukiwanie zaawansowane" type="submit">
As you can see this submit does not have id nor name defined so by.id() or by.name() cannot be used.

by.css locates elements using a CSS selector. It allows you to simply use attribute selectors for locating elements in the DOM.
element(by.css('input[type="submit"]'))

To find the form submit the by.xpath locator can be used:
element(by.xpath("//input[#type='submit']"));

What locator will suite You depends of the whole page, but here are few locators you can try:
element(by.xpath("//input[#class='jfk-button jfk-button-action dUBGpe']"));
element(by.css("jfk-button.jfk-button-action.dUBGpe"));

Related

How to configure a dynamic autocomplete in Orbeon Forms?

I need to use a dynamic autocomplete based on ws rest to show suggestions of my field. I used it but it didn't work, it didn't update the list of suggestions. Example:
<fr:autocomplete
id="control-3-control"
appearance="minimal"
labelref="#label"
resource="http://127.0.0.1/api/ws/pays/all"
bind="control-3-bind">
<xf:label ref="$form-resources/control-3/label"/>
<xf:hint ref="$form-resources/control-3/hint"/>
<xf:alert ref="$fr-resources/detail/labels/alert"/>
<xf:itemset ref="./_">
<xf:label ref=".//libelle"/>
<xf:value ref=".//id"/>
</xf:itemset>
</fr:autocomplete>
And this is the screenshot:
Doing the "filtering" based on the value entered by users is the responsibility of the service the autocomplete is calling. However, it can't do this if you don't provide it with the current value of the field. For this, use {$fr-search-value} somewhere in the URL, e.g. something like:
http://127.0.0.1/api/ws/pays/all?search={$fr-search-value}
And of course, then your service needs to take the value of the search request parameter into account. The autocomplete component will automatically call the service again and again, as necessary as users type in the field.
This allows you to search in a large dataset without having to return the whole set of possible values to Orbeon Forms.

Adding a confirmation form before the add form of a content type

One of our customers wants to add a terms of service page that has to be shown every time a user adds some specific content type, before the add form.
Any suggestions on how to implement this?
If it's a Dexterity content type, you can do this:
Create a custom form with your terms of service. In the form's button handler, redirect to the add form:
self.request.response.redirect(self.context.absolute_url() + '/++add++name.of.content.type')
Now in your type's factory info in portal_types, set the add_view_expr like this:
<property name="add_view_expr">string:${folder_url}/##terms-of-service</property>
so it goes to the custom TOS form when you click the type in the factory menu, instead of directly to the add form.
(Note: a downside of this approach is that if the user enters the URL of the add form directly, they can bypass the TOS form.)
A possible solution could be to use a cookie/session_data_manager/token/you-name-it that on the custom AddForm for that content type checks if exists.
If it doesn't redirect to that Terms of Service form that redirects back to the Addform where, now it will accept to proceed becuase the cookie/session_data_manager/token/you-name-it will be there.
An idea: when you are adding new content types (AT based content types, this will not work for Dexterity ones) you are calling
http://something/createObject?type_name=Document
You can transform the createObject script into an view that display you disclaimer form, with validation on submit.
When user accept the disclaimer you will redirect the use to something like
http://plone4.gest.unipd.it:8080/gest/it/realCreateObject?type_name=Document
where realCreateObject is a copy/paste of the original Plone createObject script.
However: the suggestion of Mathias above is really good: just add a fake checkbox field with a validation.
As mentioned in the comment of the question. I would advise adding a checkbox to the content.
For AT content you can add a BooleanField
...
atapi.BooleanField(
name='acceptConditions',
schemata='default',
required=False,
default=False,
validators=('acceptConditions', ),
widget=atapi.BooleanWidget(
label=_(u'label_accept_conditions', default='Conditions'),
description=_(
u'help_accept_conditions',
default='Please accept the <a target="_blank" '
'href="./conditions_view">'
'conditions<a/>.')
),
)
...
With a condition on the widget (In this case a browser view, which checks if the boolean field should be visible or not).
YourSchema['acceptConditions'].widget.setCondition(
'python: here.restrictedTraverse("##show_condition_field").show()')

Set class or ID on <h:inputHidden> in JSF

I'm trying to set a class or id parameter on a <h:inputHidden> in JSF. The code looks like this:
<h:inputHidden value="#{getData.name}" class="targ" />
But in the browser, the class isn't set:
<input type="hidden" name="j_idt6" value="j_idt6">
I need to set a class to this parameter, because I have a JavaScript autocomplete function for a <h:inputText> that sets a value in the hidden input, which needs to be passed in the next page.
Any ideas? Thanks!
I know it's a little bit late, but it can help someone in the future.
As inputHidden shows nothing in the browser there's no sense to allow it to have a class.
You can use the Id but as the Id could change as you change the component parents using it would bring some headache.
I'd suggest as a workaround, you can give it a parent so you can manipulate it by javascript.
Exemple:
JSF
<h:panelGroup styleClass="someCssClass">
<h:inputHidden id="someId" value="someValue" />
</h:panelGroup>
Javascript (using jQuery, you could use pure javascript also)
$('.someCssClass input[type=hidden]').val('yourNewValue');
None of these answers here satisfied my needs (need the PrimeFaces component, need class not ID, wrapping is too much work), so here's what I came up with:
Use pass-through attributes: https://www.primefaces.org/jsf-2-2-pass-through-attributes
Use pass:hidden-class="blah" (in my case, it's xmlns:pass up top)
Use [attribute=value] selector:
https://www.w3schools.com/cssref/sel_attribute_value.asp
document.querySelector multiple data-attributes in one element
That basically boils down to using something like this (because h:inputHidden becomes a regular input): document.querySelector("input[hidden-class=" + blah + "]")
Please, see similar question - How can I know the id of a JSF component so I can use in Javascript
You can sed "id" property, but in final html code it can be not the same, but composite: for example, if your input with id="myhidden" is inside form with id="myform", final input will have id="myform:myhidden".
In the end, I used a standard HTML <input type="hidden"> tag, as I had no advantages for using the JSF one. If you're trying to set a value in a hidden input with JavaScript, I recommend using this workaround.

lift jsonform id

I use SHtml.jsonForm in myjsonclass.show to wrap a jsonform to the HTML page with the following command:
<div id="form" class="lift:myjsonclass.show">
It works fine.
The SHtml.jsonForm method defines a random id for the form tag, I wonder if there is a solution to get that id and use it in the HTML. It will make easier for example to apply form validators in Javascript.
I have solved that by accessing a known element of the form and asking for its parent in javascript: element.parent(); So I am able to get id of the form with: element.attr('id').

Tapestry 5 zone inside a form

I have a form and inside it I have a country/city/etc selection.
The form is inside a zone.
When calling the onSelected for make the change of the country/city, when returning I loose the other form data. How can I keep it ?
I think a zone inside the form would help, but I am getting:
Form components may not be placed inside other Form components.
The Ubigeos type is just a component with other selects that are filled from the pais select
My .tml is
<t:zone t:id="datosPersonalesZone">
<form t:type="form" t:id="formulariodatospersonales" t:zone="datosPersonalesZone">
<t:errors/>
Sexo: <select t:type="Select" t:id="sexo" t:value="actual.sexo" model="sexo" />
PaĆ­s: <input t:type="Select" t:id="pais" model="paises" t:value="pais" t:zone="ubigeosZone"/>
<t:zone t:id="ubigeosZone">
<input t:type="Ubigeos" t:id="ubigeo_nacimiento" t:ubigeo="ubigeoNacimiento" t:zone="ubigeosZone"/>
</t:zone>
</form>
Regards !
You either have to submit a form and process country selection differently (i.e. only updating form contents by returning a block) or try using ideas from FormFragment component and TriggerFragment mixin (probably you can't use them directly but you can try extending them to support select components).
Personally, I go with first option - I have a "SubmitFormOnEvent" mixin and attach it to select-s in the form. Then I found that similar approach is demonstrated at http://jumpstart.doublenegative.com.au/jumpstart/examples/javascript/ajaxselect1 -> so you just can start with that example and update it to your needs.