How to set attribute of a webElement in Protractor? - node.js

I'm using Protractor 2 and want to change the class attribute of a webElement.
Pretend I have this menuWrapper element which I need to append show to its class attribute.
What is the easiest way to achieve this? Except for browser.executeScript().

Selenium WebDriver specification (which WebDriverJS and hence Protractor follow/use) does not have anything documented for setting an element's attribute, only for getting an element's attribute. In other words, you won't find anything built-in for this task.
Certainly, the easiest way to set an element's attribute would be to use executeScript().

Related

How to know when a property has been updated from it's connected attribute?

Given:
#property({type: Boolean, attribute: 'some-attr'}) someAttr = false;
I was expecting to see updated being fired once 'some-attr' value gets updated in the DOM.
However, updated doesn't get fired at all.
Is my expectation wrong, or should I set things up differently?
Looking at Elm's discussion of properties vs attributes, the documentation of the Html.Attributes module's attribute function, and the Elm documentation on custom elements, I am pretty sure, that this is caused by simply binding an elm expression to attribute some-attr of the LitElement based custom element. I.e. the DOM attribute will always be present and hence the corresponding property always be true.
The default converter for Boolean (activated by providing type:Boolean to the decorator) mimicks the behaviour of HTML attributes used as flags (e.g. disabled on an <input> element): If the attribute is present (no matter the value), the flag is set (true). The implementation is really straight forward, if you want to look at it in the sources: https://github.com/Polymer/lit-element/blob/master/src/lib/updating-element.ts#L163
I see these options for your problem:
Implement some extra logic in Elm to add / remove the presence of the attribute.
Create your own attribute converter for the LitElement based custom element.
Use another default converter (e.g. for String, the "default" default converter) and implement the custom logic inside the LitElement (e.g. using a derived value).
Of these 3 options, I would generally recommend the first one, as your custom element then still behaves naturally, i.e. if some-attr should be a flag (boolean attribute), then following which HTML semantics, it should be defined by its presence, not its value. This allows you to re-use it in other projects without surprising other developers.
That being said, there may of course be project-specific requirements, that are more important. E.g. if you only use this custom element in this one project with Elm, your road to success may be faster going for options 2 or 3.

How to avoid spacing in class name

Currently, I am automating a web page using Watir-webdriver with page-objects. Here I want to check a class name if checkbox checked. I need to check infra01 and checked is present if unchecked infra01 and unchecked exists or not.
<span class="infra01 infrastructure checked"></span>
<span class="infra01 digitinline unchecked"></span>
Please help how to proceed using regular expression. Also please help me how to proceed the class name with spacing.
Not sure about the page object part, but you don't necessarily need to use a regular expression. You can use the attribute_value method to get the value of class attribute in the span tag and check to see if "unchecked" is included in the returned string:
browser.span.attribute_value("class").include? "unchecked"
try to proceed with regexp:
browser.span(:class => /#{Regexp.escape("infra01 infrastructure checked")}/).when_present.click
If it possible to use "if" 1st element unchecked "else" click 2nd element

Cannot get itemDescription on f:selectItems to have an effect

The doc says:
"itemDescription: evaluates to a String that will serve as the description to be shown for the item."
http://docs.oracle.com/javaee/6/javaserverfaces/2.1/docs/vdldocs/facelets/f/selectItems.html
http://docs.oracle.com/javaee/6/javaserverfaces/2.1/docs/vdldocs/facelets/f/selectItem.html
I'm not getting any title attribute added to the resulting option element in the DOM or anything, not even when setting a literal String as its value (neither on f:selectItem nor f:selectItems, each tried seperately, the latter with a c:forEach over the list items which showed up correctly with their labels).
Some forum posts seemed to suggest people use it for tooltips.
The doc isn't being entirely clear, is the itemDescription attribute on the component even meant to be rendered as a tooltip/title? And if not, what's it good for?
I think BalusC already answered it in https://stackoverflow.com/a/25512124/3280015, which I initially overlooked.
"While creating the custom renderer, you could make use of the unused(!) description property of the UISelectItem class."
So it is currently simply unused and left for potential use by developers. Maybe that's what the Doc means by:
"for use in development tools."

Is it possible to dynamically generate the <f:validateBean> tag?

I am dynamically generating some Primefaces input and output components, and I need to be able to disable validation on these components in certain use cases, while still updating the model. (Like a save button). It looks like the proper way to do that in xhtml would be to use <f:validateBean disabled="#{myBean.someCondition}/>
However, I cannot figure out how to create this component dynamically. I searched through the javax.faces package and could not find any validateBean component. I thought maybe it would be a property that I need to set on the UIInput component, but none of the methods outlined in that API seem to what I need.
Is this possible?
Edit:
As a reference, here is the component I am creating:
UIInput input = new InputText();
input.setId(field.getFieldKey());
input.setValueExpression("value", expressionFactory.createValueExpression(elContext, field.getFieldValue(), String.class));
input.addClientBehavior("blur", ajaxBehavior);
input.addValidator(new BeanValidator());
You might want to explore these paths :
Set immediate to true on your input.
input.setImmediate(true);
Extend BeanValidator with an empty validate method and pass an instance to your input.
input.addValidator(new DummyBeanValidator());
Hope this helps.

XPages disableOutput tag issue

Has anyone experienced an issue with disableOutputTag property where if you disable output tag for a computed field control inside a repeat control and have ssjs computed content inside that tag, it won't compute the content? Is disableOutputtag property only meant to work with static content inside a repeat control or is it a bug?
I don't know whether its a bug or not, but you can emulate the behavior of disableOutputTag by removing the ID attribute from and setting the disableTheme attribute to true. Maybe this helps you in short term.
EDIT: You can refer here for more information.
Not only does this happen when placing the xp:Text control inside a repeat but in also when you create a new XPage, add a xp:text onto it and define its value like:
<xp:text value="This is a test" disableOutputTag="true"/>
In the above example the xp:text will disappear. This is not what you would have expected. I would expect that only the value would be visible on the rendered page. But I think I can explain why this happens. Since there are no tags defined (disableoutputtag) somewhere in the rendered of this component it states that it should not generate anything. Because it can not bind its id to 'nothing' and so on.
Anyway, I could not think of a scenario where I would like to render plain text without any surrounding tags. It should at least be surrounded by a span or paragraph (<p>) tag so you can style it. And an ID would be nice so I can change the contents with a partial refresh.

Resources