i18n Angular Translations - internationalization

Using the i18n ICU Select syntax, I have one dropdown working but not the other.
My xlf xml section here appears to be correct, but Angular throws parsing errors:
ERROR Error: Unable to parse ICU expression in "{VAR_SELECT, select, Asian {Asiático} ...
<trans-unit id="ethnicityTypes" datatype="html">
<source>{VAR_SELECT, select, Asian {Asian} African American {African American} Caucasian {Caucasian} Hispanic {Hispanic} Indian {Indian} Native American {Native American} Other {Other}}</source>
<target>{VAR_SELECT, select, Asian {Asiático} African American {Afroamericano} Caucasian {Caucásico} Hispanic {Hispano} Indian {Indio} Native American {Nativo americano} Other {Otro}}</target>
</trans-unit>
The associated Html dropdown is here:
<mat-form-field appearance="legacy">
<mat-select
*ngIf="ethnicitys"
placeholder="Ethnicity"
i18n-placeholder="##ethnicity"
formControlName="Ethnicity"
[disabled]="providerEdit"
[ngClass]="providerEdit ? 'disabled' : ''"
>
<!-- i18n ICU Select syntax -->
<mat-option *ngFor="let eth of ethnicitys" [(value)]="eth.UID">
<span i18n="Patient Edit modal|Ethnicity##ethnicityTypes">
{eth.EthnicityDescription, select, Asian {Asian} African American {African American} Caucasian {Caucasian} Hispanic {Hispanic} Indian {Indian} Native American {Native American} Other {Other}}
</span>
</mat-option>
</mat-select>
</mat-form-field>
Here's an example from my XLF Spanish file which works fine:
<trans-unit id="phoneTypeValue" datatype="html">
<source>{VAR_SELECT, select, Home {Home} Work {Work} Cell {Cell}}</source>
<target>{VAR_SELECT, select, Home {Casa} Work {Trabajo} Cell {Celular}}</target>
<note priority="1" from="meaning">patient-edit.modal</note>
</trans-unit>
This phoneTypeValue is associated with the following Html dropdown markup:
<mat-form-field appearance="outline" outline="never">
<mat-select
placeholder="Phone Type"
i18n-placeholder="##phoneType"
formControlName="PhoneType"
[disabled]="providerEdit"
>
<mat-option *ngFor="let pt of phoneTypes" [(value)]="pt.UID">
<span i18n="Phone Type value|The Phone Type data value##phoneTypeValue"
>{pt.PhoneTypeName, select, Home {Home} Work {Work} Cell {Cell}}</span
>
</mat-option>
</mat-select>
</mat-form-field>
The Angular line of code parsing the ICU Select message is:
const msgParts = replaceNgsp(message).split(PH_REGEXP); // value of PH_REGEXP = /�(\/?[#*]\d+):?\d*�/gi
This non-problematic message var comes back as:
'{�0�, select, Home {Casa} Work {Trabajo} Cell {Celular}}'
whereas this problematic var shows :
'{VAR_SELECT, select, Asian {Asiático} Work {Trabajo} Cell {Celular} Other {Otro}}'
So it's supposed to result in an array like this:
msgParts
['{�0�, select, Home {Casa} Work {Trabajo} Cell {Celular}}']
0: "{�0�, select, Home {Casa} Work {Trabajo} Cell {Celular}}"
length: 1
lastIndex: (...)
lastItem: (...)
[[Prototype]]: Array(0)
I don't know why Angular uses �0� (Unicode U+FFFD) here, but the VAR_SELECT section above for some reason is NOT replaced by the Unicode chars. I guess that's why it's failing.
I don't understand what's wrong.
Thanks in advance.

Related

I can't get option value without using xpath in Cabybara

I'll try to explain again. I have to get the value Arizone but I'm only getting it via xpath. The element was mapped with: element :select_cad_state, "#uniform-id_state". I don't want to use xpath to get the value Arkansas, I want to use something like: select_state.send_keys(DATA[:cad_user][:_state]) ???..etc..etc..
I want to get the arizona value from the users.yml file and pass it as an argument in the front.
############ code page #####################
<div class="selector" id="uniform-id_state" style="width: 269px;"><span style="width: 259px; user-select: none;">Florida</span><select name="id_state" id="id_state" class="form-control" style="">
<option value="">-</option>
<option value="1">Alabama</option>
<option value="2">Alaska</option>
<option value="3">Arizona</option>
<option value="4">Arkansas</option></div>
################### my PageObjects #########################
class ScreenCadastro < SitePrism::Page
set_url 'http://automationpractice.com/index.php?controller=authentication&back=my-account'
element :input_cad_company, "#company"
element :input_cad_address, "#address1"
element :input_cad_city, "#city"
element :select_state, "#uniform-id_state" (my problem is here)
################ yaml file ##############
:cad_user:
:_password: 457226
:_company: SQATest
:_address: International Drive 678
:_city: Bradenton
:_state: Arizona
################## my env file ###################
DADOS = YAML.load(File.open(File.join(File.dirname(__FILE__) + "/massa/users.yml")))
input_cad_company.send_keys(DADOS[:cad_user][:_company])
input_cad_address.send_keys(DADOS[:cad_user][:_address])
input_cad_city.send_keys(DADOS[:cad_user][:_city])
find(:xpath,'/html/body/div/div[2]/div/div[3]/div/div/form/div[2]/p[7]/div/select/option[3]').click
You are asking about option value, but from all your code it looks like you actually want to select based on the string contents of the option element (not the value). As I posted in my answer to your previous question this should just be
select_state.select(DADOS[:cad_user][:_state])
If that is not working for you please provide the error message it's giving you.

How to get text which has no HTML tag

Following is the HTML:
<div class="ajaxcourseindentfix">
<h3>CPSC 353 - Introduction to Computer Security (3) </h3>
<hr>Security goals, security systems, access controls, networks and security, integrity, cryptography fundamentals, authentication. Attacks: software, network, website; management considerations, security standards in government and industry; security issues in requirements, architecture, design, implementation, testing, operation, maintenance, acquisition, and services.
<br>
<br>Prerequisite: CPSC 253U
<span style="display: none !important"> </span> or CPSC 254
<span style="display: none !important"> </span> and CPSC 351
<span style="display: none !important"> </span>
, declared major/minor in CPSC, CPEN, or CPEI
<br>
</div>
I need to fetch the following text from this HTML:
From Line 6 - or
From Line 7 - and
, declared major/minor in CPSC, CPEN, or CPEI
I am able to get the href [Course number: CPSC 254 etc...] with the following XPath:
# This xpath gives me all the tags followed by h3 and then I iterate through them in my script.
//div[#class='ajaxcourseindentfix']/h3/following-sibling::text()[2]/following-sibling::*
Update
And, then the text with the following XPath:
# This xpath gives me all the text after the h3 tag.
//div[#class='ajaxcourseindentfix']/h3/following-sibling::text()[2]/following-sibling::text()
I need to have these course name/prerequisite in the same way they are at URL 1.
In this approach I am getting all the HREF first, then all text. Is there a better way to achieve this? I don't want to iterate over 2 XPaths to get the HREF first, then Text and after that club them to form the prerequisite string.
1 http://catalog.fullerton.edu/ajax/preview_course.php?catoid=16&coid=99648&show
Try to use below code to get required output:
div = soup.select("div.ajaxcourseindentfix")[0]
" ".join([word for word in div.stripped_strings]).split("Prerequisite: ")[-1]
The output is
'CPSC 253U or CPSC 254 and CPSC 351 , declared major/minor in CPSC, CPEN, or CPEI'

XPath to extract text within br

<div id="t_info" class="tab-pane fade active in tab">
<br><strong>Delivery</strong> <br>
<br><br><br><strong>Model Name</strong> : BP250
<br>
<br>Full HD up-scaling dramatically improves the resolution of any original content to Full HD.
<br>
<br><strong>Barcode</strong> : 8806087225921
<br>
<br><strong>Product Type</strong> : Blu-ray Player<br>
<br>Blu-Ray Disc <br>External <br></div>
I need xpath to capture the barcode value. Location of the barcode varies depending on the description.
I have tried //*[text()='Barcode'] . but i cant capture the value.
In your case you can use next XPath:
(//div[#id="t_info"]/text())[./preceding::strong[text()='Barcode']][1]
Please note that it is mauvais ton (bad manners)

WebDriver Capture Text by XPath

I am attempting to capture a line of text for an automated WebDriver test to use it in a comparison later on. However, I cannot find an XPath that will work with WebDriver. I have used the text() function before to capture text that is not in a tag, but in this instance that is not working. Here is the HTML, note that this text will never be the same, so I cannot use contains or similar functions.
<div id="content" class="center ui-content" data-role="content" role="main">
<div data-iscroll="scroller">
<div class="ui-corner-all ui-controlgroup ui-controlgroup-vertical" data-role="controlgroup">
<a class="ui-btn ui-corner-top ui-btn-hover-c" style="text-align: left" data-role="button" onclick="onDocumentClicked(21228772, "document.php?loan=********&folderseq=0&itemnum=21228772&pageCount=3&imageTypeName=1003 Application - Final&firstInitial=&lastName=")" href="#" data-corners="true" data-shadow="true" data-iconshadow="true" data-wrapperels="span" data-theme="c">
<span class="ui-btn-inner ui-corner-top">
<span class="ui-btn-text">
<img class="checkMark checkMark21228772 notViewedCompletely" width="15" height="15" title="You have not yet viewed this document." src="../images/white_dot.gif"/>
1003 Application - Final. (Jan 11 2012 5:04PM)
</span>
</span>
</a>
In this example, the text I am attempting to capture is: 1003 Application - Final. (Jan 11 2012 5:04PM)
I have inspected the element with Firebug and I have tried the following XPaths with no success.
html/body/div[1]/div[2]/div/div/a[1]/span/span
html/body/div[1]/div[2]/div/div/a[1]/span/span/text()
The WebDriver test is being written in C#.
You can either use this
driver.FindElement(By.XPath(".//div[#id='content']/following-sibling::span[#class='ui-btn-text']")
or
var elem = driver.FindElement(By.Id("Content"));
string text = string.Empty;
if(elem!=null) {
var textElem = elem.FindElement(By.Xpath(".//following-sibling::span[#class='ui-btn-text']"));
if(textElem!=null) text = textElem.Text();
}
I was able to solve this issue by removing the span tags from the XPath.
GetText("html/body/div[3]/div[2]/div/div/a[1]", SelectorType.XPath);
python webdriver code looks something like
driver.find_element_by_xpath("//span[#class='ui-btn-text']").text
But locator may be not uniqe, because I can't see all the code
PS Try to never use locators like html/body/div[1]/div[2]/div/div/a[1]/span/span
Approach:
Find the CSS Selector from the Given DOM
Derived CSS:css=#content div.ui-controlgroup > a[onclick*='onDocumentClicked'] > span > span
Use the C# Library Method to get the Text.

Locating element in same paragraph of another element in watir-webdriver

Given the following HTML code snippet; after finding the link by ID, how would you select the checkbox in the same paragraph?
For example if I wanted to select the checkbox associated with the link with ID="inst_17901-1746-1747".
The order of the paragraphs in the DIV is not consistent between sessions so I cannot select it by index or ID of the checkbox.
<div id="inst-results">
<p>
<input id="inst-results0-check" type="checkbox">
<a class="ws-rendered" id="inst_17901-1746-1747" title="!!QA Data 2/DOOR FURNITURE/316 Stainless - Altro Range"><img src="http://yr-qa-svr2/Agility/ACMSImages?type=objectType&objectTypeID=32"> <span>!!QA Data 2/DOOR FURNITURE/316 Stainless - Altro Range</span></a>
</p>
<p>
<input id="inst-results1-check" type="checkbox"><a class="ws-rendered" id="inst_17882-1746-1747" title="!!QA Data/DOOR FURNITURE/316 Stainless - Altro Range"><img src="http://yr-qa-svr2/Agility/ACMSImages?type=objectType&objectTypeID=32"> <span>!!QA Data/DOOR FURNITURE/316 Stainless - Altro Range</span></a>
</p>
</div>
I figured out this solution working off the text of the link, but Zeljko solution is much better.
$browser.div(:id,"inst-results").ps.each { |para|
if para.link.text == "!!QA Data/DOOR FURNITURE/316 Stainless - Altro Range" then
para.checkbox.set
break
end
}
If there is only one checkbox in the paragraph with the link:
browser.link(:id => "inst_17901-1746-1747").parent.checkbox.set
Works with watir-webdriver, not sure if it would work with other Watir gems.

Resources