binding locator in Protractor - protractor

I have a problem with ng-binding locator in Protractor code:
<h1 class="blackText ng-binding">some_link</h1>
I tried to use:
element(by.binding('some_link')).click();
but it's not finding anything.
This works:
element(by.cssContainingText('.ng-binding', 'some_link')).click();
but I would like to use binding locator.
Any ideas ?

See this for an example: https://docs.angularjs.org/api/ng/directive/ngBind
Note that in the example you're doing element(by.binding('name')), and not element(by.binding('Whirled')). Basically don't use what the binding evaluates to, but the binding's name.

Related

How can I locate an element by header or any particular property value in Protractor?

I have an element that have no Id defined. Class name do not allow me to identify the element uniquely.
That's why I would like to locate it using role or header property:
<p-dialog header="Deleting" showeffect="fade" role="dialog"
class="ng-tns"> </p-dialog>
How should I do that in Protractor / Selenium Webdriver?
I can do that by means of xpath, but as I understand it's rather suggested to avoid it at all.
Do I need to define my own locator using addLocator or is there simpler solution?
Protractor recommend to use css selector as first option, xpath as the secondary option when css selector can resolve your problem in some cases.
The primary reason of such recommendation considered followings:
xpath is not fast than css selector
xpath is case sensitive in some browser
for lower IE, like 6 not support xpath natively
xpath generally is longer than css selector to find same element
But css selector has two shortage which xpath is able to do:
can't find element by text
can't find parent element (only can find downward)
For your case, you can try following locator:
// css selector
p-dialog[header="Deleting"]
p-dialog[role="dialog"]
p-dialog[header="Deleting"][role="dialog"]

How to create a Smart Field control with ValueHelp feld

I need to implement a Smart Field control with Value Help in my form. I am getting json response from ODATA service. And I am setting it to a JSONModel. I have tried a sample code refering this link but I don't know how to bindElement. Please refer this JsBin
SmartControls rely on OData! However, you are using a JSONModel! Also, as #matbtt mentioned you are binding a single field to an array, but you should do it the way he mentioned above... This jsbin is the correction but still only with a JSONModel instead of an ODataModel. And this one uses OData and works just fine.
Is there a specific reason why you call an OData Service and wrap the response into a JSONModel? Do you know how to use the ODataModel in UI5?
And thank you for using my single file template!
As your data are contained in a named array you need adjust the binding as follows:
<smartField:SmartField value="{/TableCollection/0/AccountNo}" id="companyCode"/>

Babel error: JSX value should be either an expression or a quoted JSX text

I'm getting an error from Babel when trying to compile my JSX code into JS. I'm new to react so apologies if this is an obvious issue, I wasn't able to find anything about it that seemed related. I'm attempting to use props in this chunk of code, and pass a pageTitle prop to my FieldContainer component. This is giving me an issue, though, that isn't letting the code compile to JS. I discovered in my searching that prop values should be passed between {}, but adding these did not help. Any ideas? Thanks!
It's hard to tell what you are trying to do here, but as the error says, the value of an attribute must be an expression {foo} or quoted text "foo".
In this case
Child={<LoginForm />}
or
Child={LoginForm}
is probably what you want.
I got this error because I failed to quote a property inside of the JSX:
<span aria-hidden=true ...
should have been
<span aria-hidden="true" ...
Just faced same issue, I was writing
component="Contacts"
resolved it by rewriting it as:
component={Contacts}

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.

jQuery styling tricks -Check for a class name

I would like to check whether the particular sytle / class has already been applied on given element.
What is the correct jQuery function to check this?
Use .hasClass()
The Syntax is
$(selector).hasClass(classname)
Just use hasClass();
$('#mydiv').hasClass('testClass');
ie...
if($('#mydiv').hasClass('testClass')){ //YOUR CODE HERE if TRUE }