How to change the label of back button in Ionic 4? - ionic4

Given a multi language Ionic 4 application.
User can select the language.
How can I change (or more like), how can the text set to be dynamic ?
This is how far I got - but of course this isn't working:
<ion-back-button [text]="{{ app.button.back | translate }}"></ion-back-button>
UPDATE:
I meant by not working, I get the following error:
Parser Error: Got interpolation ({{}}) where expression was expected at
column 0 in [{{ app.button.back | translate }}]

You are combining two features here:
[text]="{{ app.button.back | translate }}"
You just need to remove the [] so its not expecting a javascript value:
<ion-back-button text="{{ 'app.button.back' | translate }}"></ion-back-button>

You can use this method in ionic 4:
<ion-back-button [defaultHref]="defaultHref" slot="start" text="{{ 'SIGNUP.BACK' | translate }}">

In ionic 6 you can use a small hack:
const Ionic = (window as any as IonicWindow).Ionic;
(Ionic.config as Map<string, string>).set("backButtonText","MyBackText");

Related

Using #ng-select/ng-select 9.0.2. and Angular 14. AddTag not working properly. Add tag in angular form send value as null

Add tag in angular form send value as null
<ng-select [items]="[]" [addTag]="true" [multiple]="true" bindLabel="name" bindValue="value" [(ngModel)]="applicable-to-status-codes" [closeOnSelect]="false" formControlName="applicable-to-status-codes"></ng-select>
{{formGroup.value | json }}
<ng-select [items]="[]" [addTag]="true" [multiple]="true" bindLabel="name" bindValue="value" [(ngModel)]="applicable-to-status-codes" [closeOnSelect]="false" formControlName="applicable-to-status-codes"></ng-select>
You forget to add closing double quotation on bindValue="value" make sure, you are following the syntax accordingly.

Break long word at specific point in React Native

I am relatively new to React Native and styling with flex and have been looking for a way to break a long word at a specific point. I only want an optional break in case the word gets too long.
In case 1 (see example) I don't want to break the word, since the component is big enough.
In case 2 the component is too small so the word breaks. I would like to be able to control the breaking position to get something as in case 3.
I am looking for something similar to this solution for HTML, but I cannot use <wbr> or ​ and could not find an equivalent for React Native, if something like that exists.
I have tried using \u00AD as suggested here, but it doesn't seem to insert a break.
Example:
// case1
––––––––––––––––––––––––––––––––––––––––––––––
|ReallyLongWordThatBreaksSomewhere |
| |
––––––––––––––––––––––––––––––––––––––––––––––
// case2
–––––––––––––––––––––––
|ReallyLongWordThatBre|
|aksSomewhere |
| |
–––––––––––––––––––––––
// case3
–––––––––––––––––––––––
|ReallyLongWord |
|ThatBreaks |
|Somewhere |
–––––––––––––––––––––––

How to extract the text within an HTML tag (in Selenium IDE)?

The html looks something like this:
<p>
sometext1
<br>
sometext2
<br>
sometext3
</p>
I would like to extract all the text between the paragraph tags, including the <br> tags.
I tried to use storeText function, but it stores only the text, without the tags.
I could store the entire HTML source and then extract what I need in Perl, but I was wondering if there is a way to store a block of HTML code using a specific xpath (e.g. store the HTML code for the third table in the webpage inside a variable).
innerHTML
i will try with document.getElementById('id').innerHTML
you could use a getEval() with Javascript that return the innerHTML of the element. You'll have to find it in javascript, though
#Tarun: I would if I could man....
#Grooveek: Thanks man, that worked.
I used:
storeEval | window.document.getElementsByTagName("p").item(9).innerHTML | p
This saved the content of the 9th paragrah in the variable p.
I had to use getElementsByTagName because the tags had no id's.
For more accuracy, one could use getElementById function insted:
storeEval | window.document.getElementById("id of element").innerHTML | p
Hope this will help other people too.
Thanks again.
I suggest this:
from selenium import webdriver
driver = webdriver.Firefox()
driver.get("url")
element = driver.find_element_by_tag_name("p")
text = element.text
But keep in mind if you are dealing with text-boxes, you can't use .text; it returns None. In that case you should use .get_attribute("value"), and when ever you are unable to catch what you want, you can use .get_attribute("innerHTML").
getAttribute("innerHTML"); works for me
I propose to find it by a class name, not all objects have it's Id.
storeEval | window.document.getElementsByClassName('*classname*')[0].innerHTML; | HTMLContent
number 0 will return first occurence. If there is more than one element, choose proper number, or get the number of class occurencies by .length
storeEval | window.document.getElementsByClassName('*classname*').length; | ClassCount

Clicking on several links part dynamically generated

I'm new in Selenium and testing matters.
I'm trying to capture the id of an hyperlink element that is dynamically part generated.
The click action is recorded like as below when i make click on in selenium, the part in bold are dynamically generated, there are many of them on my page and can differ from one site to another(I'm testing cms). I'd like to capture and click on any one.
This is what I've tried to do since:
storeAttribute | //button#class onclick="setLocation(javascript{baseUrlSelection()}['/checkout/cart/add/uenc/(a-zA-Z0-9)/product/(0-9)]'')" | myid
echo | ${myid} |
clickAndWait | ${myid[0]}
It doesn't work
My links looks like this when click action is recorded in selenium:
buton[#onclick="setLocation('http://localhost/mydomaine/index.php/checkout/cart/add/uenc/aHR0cDovL2xvY2FsaG9zdC9NYWdlbnRvSGls
YWlyZURlbW9WMi9tYWdlbnRvZGVtb0hpbGFpcmVWMi9pbmRleC5waHAvY2F0ZWdvcmllMS5odG1sP19fX1NJRD1V/product/1/')">
Please Help.
Are you using the Selenium IDE? It would probably be much easier to do something using the other development environments, however if you really want to do looping:
Get the looping user-extension from this page
and run a script like this.
store | 0 | myCurrent
storeEval | var pattern=new RegExp("\\w*http://localhost/mydomaine/index.php/checkout/cart/add\\w*");var i=0;var total=0;while(i<window.document.getElementsByTagName('input').length){if (window.document.getElementsByTagName('input')[i].id.match(pattern)){window.document.getElementsByTagName('input')[i].id = 'testID_' + total;total=total+1;}i=i+1;}total; | myTotal
while | storedVars.myCurrent < storedVars.myTotal
storeAttribute | //input[contains(#id,'testID_${myCurrent}')]#class | myid
echo | ${myid}
clickAndWait | //input[contains(#id,'testID_${myCurrent}')]
store | javascript{storedVars.myCurrent++}
endWhile
What does the click on these buttons do? Does it postback the page or anything like that? If so, you'll need to move the storeEval | var pattern.... inside the while loop. What the javascript does is rename all of the inputs on the page that match the RegEx pattern (which you'll probably need to change to match your button ID's) to a sequential ID so you can loop through them easily. If there is a different pattern you can exploit, feel free to do that.
Javascript adapted from here
You can use the xpath contains() function to locate the items:
storeAttribute | //input[contains(#onclick,"setLocation('http://localhost/mydomaine/index.php/checkout/cart/add/uenc/")]#class | myid
echo | ${myid}
clickAndWait | //input[contains(#onclick,"setLocation('http://localhost/mydomaine/index.php/checkout/cart/add/uenc/")]#class
It is also a good idea to reference the elements by something other than their onclick attribute. Id or name would be good choices.

Selenium: How do I use javascript to clear a value from a form field?

I'm using the selenium IDE and the Selenium-Fitnesse Bridge fixture and I'm trying to test that when I clear a default value out of a form field, my form displays an error message.
So when I record with the Selenium IDE, what it does is the equivalent of telling Selenium to type nothing.
| type | text_field | |
The problem with this is that the Fitnesse fixture I'm using expects that second argument to not be null.
Is there a way in Selenium to "clear a value" rather than "typing nothing"?
You can do it via javascript as such:
| verifyEval | javascript{this.browserbot.getCurrentWindow().document.getElementById('CONTROL_ID').value = ''} ||
Effectively the verifyEval statement allows you to execute any piece of javascript that you'd like. Makes some difficult problems to accomplish with Selenium much simpler.
I used this tutorial (today believe it or not) to figure things out.
I used this to get it to work. reg_start_date is the id of my input field.
| storeEval | window.document.getElementById('reg_start_date').value = '' |
From the selenium reference:
Note that, by default, the snippet will run in the context of the "selenium" object itself, so this will refer to the Selenium object. Use window to refer to the window of your application, e.g. window.document.getElementById('foo')
Also, avoid wrapping the javascript code with javascript{}, it will not work.
We had this issue at the beginning as well. Try: | type | text_field | blank |
Look for more info on the Fitnesse documentation for the use of blank and null.
:)