How to get Error message when using pattern in angular 2 - validation

I have tried this code but it is not working.
<div>
<span *ngIf="!usernameRef.errors?.required">Amount</span>
<span *ngIf="!usernameRef.errors?.required">Cover amount required.</span>
<span *ngIf="usernameRef.errors?.pattern">Cover amount invalid.</span>
<input type="number" name="Amount" class="form-control" data-field="validate" placeholder="50 000" [(ngModel)]="Amount"
required #usernameRef="ngModel" pattern="[0-9]*" />
</div>

Your regex is also valid from two reasons:
Your input type is a number. You can't type letters.
[0-9]* - the asterisk means - 0 or more occurrences.

Related

Rspec + Capybara: How can I use expect to validate all items in a field?

Brothers help me please. I need to validate the values ​​of this combo, I tried it with a command I found here but I still haven't had success. The error I'm getting is: Reason:
Ambiguous match, found 7 elements matching visible option nil
----------------------------------------------
I noticed that the first value is white I don't know if this is the error but I tried to get it for a specific value and I couldn't do it either!!
My Code:
class Screen_Grupo_Intervencao < SitePrism::Page
include RSpec::Mocks::ExampleMethods::ExpectHost
include RSpec::Matchers
element :estrutura, :xpath, '//*[#name="_lyXWFMTGINID_ALAY"]'
all(screen_grupo_intervencao.estrutura select)1.should have_text('CADASTRO TÉCNICO D&C - DISTRIBUIÇÃO E COLETA ENGENHARIA GESTÃO DE PERDAS GSC COMERCIAL GSO OPERACIONAL')
<select style="padding-right:0px;width:100%;" class="f fA" onrealchange="return true;" onchange="setTooltip(this,'');realChangeListener(event);" id="686" name="_lyXWFMTGINID_ALAY" tabindex="151" evidence="">
<option title="" selected="" value="" class="f fA" style="border:0px;border-radius:0px;font-size:1em;box-shadow:none;"></option>
<option title="" value="61" class="f fA" style="border:0px;border-radius:0px;font-size:1em;box-shadow:none;">CADASTRO TÉCNICO</option>
<option title="" value="41" class="f fA" style="border:0px;border-radius:0px;font-size:1em;box-shadow:none;">D&C - DISTRIBUIÇÃO E COLETA</option>
<option title="" value="62" class="f fA" style="border:0px;border-radius:0px;font-size:1em;box-shadow:none;">ENGENHARIA</option>
<option title="" value="63" class="f fA" style="border:0px;border-radius:0px;font-size:1em;box-shadow:none;">GESTÃO DE PERDAS</option>
<option title="" value="1" class="f fA" style="border:0px;border-radius:0px;font-size:1em;box-shadow:none;">GSC COMERCIAL</option>
<option title="" value="21" class="f fA" style="border:0px;border-radius:0px;font-size:1em;box-shadow:none;">GSO OPERACIONAL</option>
</select>
It would be a big help if you read the Stackoverflow instructions on inserting code into questions so it would format it correctly. Also the code you're showing somehow has a linked '1' stuck in the middle of it.
The error you're getting is because you have specified element :estrutura, :xpath, '//*[#name="_lyXWFMTGINID_ALAY"]' which means there should be only 1 of them. However on your page there are apparently 7 elements matching the xpath. Either make the selector more specific so it only matches one thing, or change it to elements :estrutura, :xpath, '//*[#name="_lyXWFMTGINID_ALAY"]' so it allows multiple elements to be found.
I would also suggest to stop using xpath when it's not necessary - elements :estrutura, '[name="_lyXWFMTGINID_ALAY"]'
Assuming you are meant to have multiple matching elements on the page and I'm reading you're code right then I think you'd be doing
screen_grupo_intervencao.estrutura[1].should have_text('CADASTRO TÉCNICO D&C - DISTRIBUIÇÃO E COLETA ENGENHARIA GESTÃO DE PERDAS GSC COMERCIAL GSO OPERACIONAL')
although that seems like a strange way to be testing.

XPath: Matching a text between two similar tags

I'm trying to scrape a website with messy structure, the text I'm requiring is laying between the first 5 consecutive br tags (No more and no less, exactly 5) and the following 2 consecutive br tags.
It looks like this:
<p class="A">
"Some text"
<br>
"Some text"
<br>
<br>
"Some text"
<br>
<br>
<br>
<br>
<br>
"Required text"
<br>
"Required text"
<br>
"Required text"
<br>
<br>
</p>
Scrapy converts <br> tags to newline characters, so you can just extract the whole text and split it at 5 newline characters:
> text = sel.xpath('//text()').extract()
['\n"Some text"\n', '\n"Some text"\n', ...]
> values = ''.join(text).split('\n\n\n\n\n')[1]
'\n"Required text"\n\n"Required text"\n\n"Required text"\n\n\n'
> values.strip().split('\n\n')
['"Required text"', '"Required text"', '"Required text"']

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'

How to write xpath

I want to get text "+12345" from this HTML
<p class="Test" ng-repeat="(k, wl) in partnerEditModel.td">
<span id="Test-update-12345" class="ng-binding">
+12345
<span class="err-message ng-binding">Error</span>
</span>
<a id="mibile" class="button" ng-click="remove(k)">
</p>
I have written "//p[#class='Test']/span but it matched "+12345Error" which I have just wanted "+12345" (I have not wanted "Error".)
Could you please tell me about how to write this xpath?
Try below XPath expression to get "+12345" only:
normalize-space(//span[#id="Test-update-12345"]/text()[1])
Try below code in robot framework
${var}= | Get Text | xpath=//span[span[#class='err-message ng-binding']]
Log | ${var}
Try using below:
xpath=//p[#class='Test']/span[1]

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