Python Selenium Firefox <input type="date" /> select with .click() - python-3.x

I know there are lots of these out there, but none has proved helpful yet. I cannot find the popup calendar no matter how hard I try. Any suggestions?
html:
<label for="id_start_date">Start Date</label>
<input class="form-control" id="id_start_date" type="date" value="" />
test file:
start_date = self.browser.find_element_by_id('id_start_date')
start_date_label = self.browser.find_element_by_xpath(
"//label[#for='id_start_date']"
)
self.assertEqual('Start Date', start_date_label.text)
# Today's Date is preloaded into the field. Jeff clicks on it
# and it pops open a little calender to choose a date.
start_date.click()
"""
What is supposed to go here so I can find and select my desired date?
"""
It does show up on my page when I manually check it. I am at a complete loss.

You don't have to click on the calendar. you can set the value because it is of the type "input".
Pay attention to the format of date, assuming that it is in the format (MM/dd/yyyy) the code below works.
start_date = self.browser.find_element_by_id('id_start_date')
start_date.clear() # clear any value that was in the field before (if you don't clear, will append the new string sent.)
start_date.send_keys("08/17/2018")

Related

How to refresh the data while entring date through VBA on webpage?

Date field is a date picker textbox on webpage. While manually date entered on field, it was refreshed data based on date. below is a HTML code of that particular.
Any help or input would be appreciated. Thanks you!!
<div class="input-group input-group-sm">
<input id="_txtFromDt" class="form-control dateselector ng-pristine ng-untouched ng-valid ng-isolate-scope ng-valid-maxlength ng-valid-date" type="text" ng-class="{'isonlyicon':isonlyicon}" ng-change="datePickerChange()" init-date="initialdate" ng-focus="DatePickerFocus()" ng-keypress="isNumeric($event)" ng-blur="checkDate()" ng-disabled="datedisable" default="From Date" key="txtFromDt" name="calDate" maxlength="10" date-disabled="disabled(date, mode)" ng-model="ngmodels" mxdate="ngmodels" show-button-bar="false" show-weeks="false" close-text="Close" datepicker-options="dateOptions" max-date="maxdate" min-date="mindate" is-open="isopened" title="Enter Date in DD/MM/YYYY Format" placeholder="From Date" datepicker-popup="dd/MM/yyyy" pageid="" resource="Mx_PageDetail"/>

Checking to see if on last option of dropdown in selenium

I'm trying to make a program that is going to keep clicking on the listingnextbtn button until it reaches the last page, the website design makes this tricky so the only way I can do it is by detected that it is on the last option of the page number list dropdown.
<div id="pgn-nav" class="pgn-nav">
<a id="listingNextBtn" class="btn blue disabled" role="button" href="#"><span class="btn-txt bg-grey">Prev</span></a>
<select id="listingPageNumber" class="pageNumber">
<option value="1">1 - 150</option><option value="2">151 - 300</option><option value="3">301 - 450</option><option value="4">451 - 600</option><option value="5">601 - 750</option><option value="6">751 - 900</option><option value="7">901 - 916</option>
</select>
<a id="listingNextBtn" class="btn blue" role="button" href="#"><span class="btn-txt bg-grey">Next</span></a>
</div>
I just have no idea how to check to see if its on the last option, everything else is pretty straightforward.
EDIT:
The code I have for this portion so far.
try:
barack = soup.find(id='listingPageNumber')
#if barack == last object
print('Reached last dropdown object)
#do something, like click button
except:
print('Not at the end of listpage yet')
Your goal is not clear, so the code might not fit it well
You can try to do as below:
from selenium.webdriver.support.ui import Select
# Define Select object
select = Select(driver.find_element_by_id("listingPageNumber"))
# Get currently selected option
current = select.all_selected_options[0].text
# Get last option in the list of available options
last = [option.text for option in select.options][-1]
# Check if current option is the last option
if current == last:
print("Last option is selected")

How to click Save button on a web form using VBA

I am working on automating a task. I want to click a Save button on a web form using VBA, but it's not working:
<input name="save" title="Save" class="btn" type="submit" value=" Save ">
<input name="save" tabindex="79" title="Save" class="btn" type="submit" value=" Save ">
I've tried ie.Document.all("save").Click, but it doesn't seem to work. What method do I need to click the button?
You can try going through all your "btn" class collection, and click the one with your save value:
Dim btnClassColl As Object, btn As Object
Set btnClassColl = ie.document.getElementsByClassName("btn")
For Each btn In btnClassColl
If btn.Value Like "*save*" Then
btn.Click
Exit For
End If
Next
Also: make sure that your web page has FULLY loaded before trying to automate anything.
Edit
In response to the comment:
This code is neither giving error nor its clicking on btn. Can this be because there are two buttons on web page with same name and function?
An alternative solution would be that if you know the index number of the collection item, you can simply use that index number and not loop at all. In this case, your index # is 1 (remember: Base 0).
Try this alternative:
Dim btn As Object
ie.document.getElementsByName("save")(1) '1 actually means #2 in index

How to have Angular2-MDL-ext Select placeholder grayed out

Is it possible to have the select placeholder grayed out coherently with other Angular 2 MDL form fields?
This is what I can obtain with default settings:
<mdl-textfield type="text" label="CAP..." formControlName="postcode" floating-label></mdl-textfield><br>
<mdl-textfield type="text" label="Città..." formControlName="city" floating-label></mdl-textfield><br>
<mdl-textfield type="text" label="Provincia..." formControlName="province" floating-label></mdl-textfield><br>
<mdl-select
placeholder="Nazione"
formControlName="countryid">
<mdl-option value="0"></mdl-option>
<mdl-option *ngFor="let country of countries" [value]="country.id">{{country.name}}</mdl-option>
</mdl-select>
The select placeholder "Nazione" appears in black. I'd like to have it grayed out just as the field "Cap...", "Città...", "Provincia...".
mdl2-angular-ext 0.6.0 should have proper placeholders now. You example code is correct, but for anyone else visiting this question, here's the code (again):
<mdl-select
placeholder="Nazione"
formControlName="countryid">
<mdl-option value="0"></mdl-option>
<mdl-option *ngFor="let country of countries" [value]="country.id">{{country.name}}</mdl-option>
</mdl-select>
Unrelated to your question, but since it was discussed in the comments regarding the question, the floating-label property works now too.
<mdl-select floating-label
placeholder="Nazione"
formControlName="countryid">
<mdl-option value="0"></mdl-option>
<mdl-option *ngFor="let country of countries" [value]="country.id">{{country.name}}</mdl-option>
</mdl-select>

setting textarea text based on current input field

I have two input fields
input(ng-model='form.firstName', name='firstName', id='familyName')
and
input(ng-model='form.lastName', name='lastName')
I also have a textarea field
textarea(id='fieldInfo', ng-model='fieldInfo', name='fieldInfo' cols='15', rows='10')
I would like to change the text in the TextArea to "Please enter your first name" when the focus or cursor is in the First Name input and change it to "Please enter your last name" when the is on the last name inout and it should be able to toggle as the user switches focus from first name to last name and last name to first name.
Any assistance will be much appreciated.
Melroy
The ng-focus directive will not work for you if you are using one of the stable 1.0.x versions of AngularJS. However, I have created a working CodePen example of how you could do it without the ng-focus directive.
I created my own on-focus directive that evaluates an expression, which results in an update to the scope model being used by the textarea. I'm sure it could use some refinement, but the concept should still work for your application.
You can use the ngFocus directive if you are using angular 1.2.0.
In your controller:
var myApp = angular.module('myApp',[]);
myApp.controller('MyCtrl', ['$scope', function($scope) {
$scope.text = "";
}]);
And in your view:
<input type="text" data-ng-model="form.name" ng-focus="text = 'Please enter your first name'" />
<input type="text" data-ng-model="form.last" ng-focus="text = 'Please enter your last name'" />
<textarea name="area" id="textarea" cols="30" rows="10"> {{ text }} </textarea>
You can check this fiddle
Edit: Wrong fiddle link

Resources