How to verify presence of multiple text in Selenium - selenium

I want to verify one of the metadata present in to div as :
<div ng-if="XXXXXXX" class="XXXXX" >
<div>March 01 2019, 10:00 am to</div>
<div>March 28 2019, 6:00 pm</div>
</div>
Need to verify presence of all these Keywords with '01', '28', '10:00 am', '6:00 pm' except Month and Year.
What can be effective way to verify it ?

The parent <div> will hold all the text. Locate it and check if it contains it
WebElement element = driver.findElement(By.className("XXXXX"));
String text = element.getText();
if (text.contains("01") && text.contains("28") && ...) {
assertTrue(true, "All keywords present");
}

Related

How to insert conditional text in a p tag on a cshtml page

I Have this portion of cshtml page part of my Razor application:
<p style="text-align: justify">
thank you for confirming your reservation for the <b>#{ #Model.HotelChoiceDescription.Substring(#Model.HotelChoiceDescription.IndexOf("_") + 1) }</b>
</p>
if (!string.IsNullOrEmpty(Model.TypeOfRoomDescription))
{
<!-- Verify if english -->
if (Model.TypeOfRoomDescription.Contains("#STARTENG#") && Model.TypeOfRoomDescription.Contains("#ENDENG#"))
{
<p style="text-align: justify">
#(new HtmlString(Model.TypeOfRoomDescription.Substring(Model.TypeOfRoomDescription.IndexOf("#STARTENG#") + 10, Model.TypeOfRoomDescription.IndexOf("#ENDENG#") - Model.TypeOfRoomDescription.IndexOf("#STARTENG#") - 10))) for the period #Model.ReservationDate
</p>
}
<!-- default -->
if (!Model.TypeOfRoomDescription.Contains("#STARTENG#") && !Model.TypeOfRoomDescription.Contains("#STARTITA#"))
{
<p style="text-align: justify">
#(new HtmlString(Model.TypeOfRoomDescription)) for the period #Model.ReservationDate
</p>
}
}
The result is:
thank you for confirming your reservation for the Giant Hotel
Single room (eur. 44,00/night) for the period August 20, 2022 - August 27, 2022.
But to reduce the spaces and consequently the pages to be printed, the best result would be this:
thank you for confirming your reservation for the Giant Hotel Single room (eur. 44,00/night) for the period August 20, 2022 - August 27, 2022.
All the text in the same paragraph
I tried to put everything inside the first tag p but it also prints the if and the "{"
I also tried entering #if, but it doesn't load the page because it goes in error
You can try to only use a <p></p>:
<p style="text-align: justify">
thank you for confirming your reservation for the <b>#{ #Model.HotelChoiceDescription.Substring(#Model.HotelChoiceDescription.IndexOf("_") + 1) }</b>
#if (!string.IsNullOrEmpty(Model.TypeOfRoomDescription))
{
<!-- Verify if english -->
if (Model.TypeOfRoomDescription.Contains("#STARTENG#") && Model.TypeOfRoomDescription.Contains("#ENDENG#"))
{
#(new HtmlString(Model.TypeOfRoomDescription.Substring(Model.TypeOfRoomDescription.IndexOf("#STARTENG#") + 10, Model.TypeOfRoomDescription.IndexOf("#ENDENG#") - Model.TypeOfRoomDescription.IndexOf("#STARTENG#") - 10)+" for the period "+Model.ReservationDate))
}
<!-- default -->
if (!Model.TypeOfRoomDescription.Contains("#STARTENG#") && !Model.TypeOfRoomDescription.Contains("#STARTITA#"))
{
#(new HtmlString(Model.TypeOfRoomDescription+" for the period "+Model.ReservationDate))
}
}
</p>
then the result will be in a line:
thank you for confirming your reservation for the Giant Hotel Single room (eur. 44,00/night) for the period August 20, 2022 - August 27, 2022.

Show date from database on Picker materialize

I have the following code, when I click on the Picker I want to see the date 01/01/2018 selected in the calendar.
I need the calendar to select the date that contains the value of the imput.
$var_date = '01/01/2018';
<input type="text" name="date" name="date" class="datepicker" value="<?php echo $var_date; ?>">
<label for="first_name">Date</label>
This can be done with the help of instance.setDate(new Date()).
<input type="text" class="datepicker">
<script>
document.addEventListener('DOMContentLoaded', function () {
var elems = document.querySelector('.datepicker');
var instance = M.Datepicker.init(elems);
// instance.open(); This will open your datepicker on its own when page is loaded completely
instance.setDate(new Date(2018, 2, 8));
});
</script>
Note- new Date(year, monthIndex [, day [, hours [, minutes [, seconds [, milliseconds]]]]]);
The argument monthIndex is 0-based. This means that January = 0 and December = 11
MDN - Date
Materialize - Pickers

Default value pre-selected in select box with ng-options

I am trying to get default value selected (from database) in my select box using ng-options.
My view
<select class="form-control samlength modalinput"
ng-options="p.procid as p.procname for p in processes track by p.procid"
ng-model="p.procid">
<option value="">-- choose an option --</option>
</select>
where p.procid is a value received from the database.
My data
procid procname time
1 MyProcess 2018-05-30 13:34:54.097 3003162
3 Testing 2018-05-31 18:31:32.467 3003162
If selected procid is 3, how can I get it to be selected by default?
FYI - I have tried multiple answers given in other threads. I have also tried ng-init but nothing helped.
You can keep your HTML as:
<select class="form-control samlength modalinput"
ng-options="p.procid as p.procname for p in processes track by p.procid"
ng-model="selectedProcess">
<option value="">-- choose an option --</option>
</select>
Now if we have a requirement to select a particular object in the array. We can do that by iterating through the array and comparing value at the given key:
function functiontofindIndexByKeyValue(arraytosearch, key, valuetosearch) {
for (var i = 0; i < arraytosearch.length; i++) {
if (arraytosearch[i][key] == valuetosearch) {
return i;
}
}
return null;
}
Call this function as:
var index = functiontofindIndexByKeyValue($scope.processes, "procid", procid);
$scope.selectedProcess = $scope.processes[index];
alert(index);
Hope it works!
Update your html code to this:
<select ng-model="processSelected"
ng-options="p.procname for p in processes track by p.procid">
</select>
Then in controller initialise your model value as:
$scope.processSelected = $scope.processes[1];
Where $scope.processes is an array of process objects.
Plunker Example

ngx-bootstrap DatePicker, how to set display format for date

How do I set a custom format for the date the datepicker displays?
I'd like a long date format like 'November 4, 2017' or '4 Nov, 2017'. Something that's clear for multiple locals.
I've experimented with different properties of the options, but always end up with US short date format.
To display date in 'November 4, 2017' format use the following config:
this.bsConfig = Object.assign({}, {
dateInputFormat: 'LL',
locale: 'en-gb'
});
And assign it to the date picker in html component:
<input ... bsDatepicker [bsConfig]="bsConfig" />
Note there is an existing issue when patching form value. The link contains a possible workaround as well.
To display date '4, Nov 2017' in this format.
use this config in html.
[bsConfig]="{dateInputFormat: 'D MMMM YYYY '}"
It works for me.

DateTime has wrong value after submit

I have a dropdown list with dates, the values are as such:
<select name="DayDate" id="DayDate" data-val-date="The field DayDate must be a date." data-val="true" style="display: inline-block;" class="input-validation-error">
<option value="07/11/2013">donderdag 11 juli 2013</option>
<option value="07/10/2013">woensdag 10 juli 2013</option>
<option value="07/09/2013">dinsdag 9 juli 2013</option>
</select>
#Html.DropDownListFor(m => m.DayDate, Model.Days.Select(r => new SelectListItem
{
Text = r.Date.Value.ToString("D"),
Value = r.Date.Value.ToString("MM/dd/yyyy", CultureInfo.InvariantCulture)
}))
But when I submit I get as a date 7th of November, 7th of October or 7th of September!
The Thread culture is set to NL-nl and this has to remain this way.
So I thought of removing CultureInfo.InvariantCulture but then the model won't accept the date input data-val will be false, with this error: The field DayDate must be a date.
The following is set in the web.config
<globalization culture="nl-NL" uiCulture="nl-NL" />
How can I get the correct dates passed on?
Solved it by adding this piece of Javascript:
$.validator.methods.date = function (value, element) {
return true;
};