Selenium Google Trends Custom period - selenium

I am trying to get daily data from Google trends using Selenium.
Therefore, I need to Input the start and end date in both boxes. For the start date, I use the following which works fine:
elem4 = browser.find_element_by_class_name("md-datepicker-input")
elem4.clear()
elem4.send_keys("01/01/2018")
However, the second box has the same class name 'md-datepicker-input'.
Picking it via xpath also doesnt work...
Has anyone an idea how to select that box, clear it and input my data?
Example custom period

Here is the CSS that you should use for To date.
.custom-date-picker-dialog-range-to .md-datepicker-inpt
If you want to use xpath
//div[#class='custom-date-picker-dialog-range-to']//input[#class='md-datepicker-input']

Related

Selenium select date from a calendar- unable to find x path

I am trying to select a date from the calendar. However sendkeys does not send data. After I click on the field calendar month drops down. Right click reveals nothing. I have tried in Firefox and Chrome.
http://demo.guru99.com/V4/manager/addcustomerpage.php
username: mngr284483
password: AjerYbu
#FindBy(xpath = "//input[#name='dob']")
private WebElement selectCustomerDOB;
public void sendDOB(String dob){
selectCustomerDOB.sendKeys(dob);
}
I have tested with Thread.sleep to make sure it is not a timing issue.
What can I do in this case to select a date? Thanks in advance for your time and ideas.
Since you are using an element with type 'date', it is up to the browser to render the calendar, or anything else to allow users to select the date. The date picker is not part of your web page and so you would not be able to find its locators in the conventional ways.
I believe your testing requirement is to be able to check how your application behaves when different dates are selected, rather than to see if the date picker works (which the browser would take care for you).
In order to select dates, you should be able to use send keys if you gave the value in the right format (yyyy-MM-dd). I tested with the given website using Selenium IDE and things seem to work.
WebElement selectCustomerDOB = driver.findElementById("dob"); // While xPath is great and your xPath is valid - I feel ID is much faster.
selectCustomerDob.sendKeys("2011-12-21");

Protractor sendKeys issue with scripted input fields

I'm automating e2e tests with Protractor on an angular app.
However, I have an issue when sending keys on input fields.
The sendKeys would miss few characters everytime so I found a workaround :
static sendKeys(value, element){
value.split('').forEach((c) => element.sendKeys(c));
}
This works well but it takes more than 3 times the time the original sendKeys function would.
Well no problem my tests are still functionnal right ?
My app now has new fields with scripts behind them.
One of them is a datepicker input, you can either choose from the datePicker or type it manually. However, for today's date you would type 09022018 and the slashes are automatically appended at the right place (like so 09/02/2018). If you were to enter a wrong date the field is cleared.
Now back to the problem : it seems that both my implementation of sendKeys and the original one loose focus after each submitted key. This means that I can't enter a valid date in the input field as it's cleared after each simulated keypress.
I could use browser.executeScript to fix it but I wouldn't be able to test the functionnality adding slashes. Also, as you type, the datepicker is still open and refreshes after each keypress, you can select a date from it at any time and that is also a feature I want to test.
Thanks in advance
Use executeScript to set the date in backgrond, then use sendKeys to enter a space or Tab at the end to trigger the Keyborad event which will check the input and format the input with slash
function enterDate(date) {
var script = 'arguments[0].value=arguments[1]';
// input box for date
var dateBox = element(by.xxx(yyy));
browser.executeScript(script, dateBox, date);
dateBox.sendKeys(" ");
// or try send Tab
dateBox.sendKeys(protractor.Key.TAB);
}
enterDate('09022018');
You can try this solution on other fields you fixed but take 3 more time.

Capybara, selecting 1st option from dropdown?

I've done a search and most of the related google results have returned just in general selecting an element from a dropdown. However the ID's in this case for the elements in the dropdown are dynamically generated unfortunately.
This is for a base test case, so I basically just need to select for example the first one. The text is also the same for the elements in the dropdown (not sure if that helps).
Is there such an example of this?
Im using cucumber with caybara(using selenium driver) integration
You can find the first option element and then use the select_option method to select it.
For example, if the select list has an id "select_id", you can do:
first('#select_id option').select_option
As #TomWalpole mentions, this will not wait for the element to appear. It would be safer to do one of the following:
first('#select_id option', minimum: 1).select_option
or
find('#select_id option:first-of-type').select_option
Alternatively you can get the first element text then select it by select function:
first_element = find("#id_of_dropdown > option:nth-child(1)").text
select(first_element, :from => "id_of_dropdown")
After two days of searching and reading, this article was amongst one of a few that was helpful. Hopefully, this can help someone else!
I created a few methods like so, excuse the naming..I changed it.
def some_dropdown(id, text)
dropdown = find(id).click
dropdown.first('option', text: text).select_option
end
def select_form
within 'content#id' do
some_dropdown('#id', text)
click_link_or_button 'Submit'
end
end
I also referenced this.
I've tried to select an option from a modal dropdown. After trying all listed methods, and many other from other threads - I totally gave up and instead of using clicks or select_option just used keyboard keys
find(:select, "funding").send_keys :enter, :down, :enter
In case it still complains - try:
find(:select, "funding", visible: false).send_keys :enter, :down, :enter
Worked like a charm, selecting first option from a dropdown.

Xpages - Dojo Value Picker [multiple choice, other db, search function]

I need to build a dojo value picker that has the following capabilities:
1) Be able to choose views from a different DB
2) Be able to choose multiple values
3) Be able to have the user search for a value
I cannot figure out how to get all three.
A simple value picker appears to not support search.
If I user a dominoViewValuePicker, I cannot have both dojo types:
extlib.dijit.PickerCheckbox
and
extlib dijit pickerlistsearch
Can someone tell me what I am doing wrong?
Thanks to Paul and others for helping. I did get this to work by using the dominoViewValuePicker. See my example below, which I hope could help someone else.
<xe:valuePicker id="valuePicker1"
dialogTitle="Choose From This List" pickerIcon="/picker.png"
for="Approvers" dojoType="extlib.dijit.PickerListSearch">
<xe:this.dataProvider>
<xe:dominoViewValuePicker viewName="(YOURVIEWNAME)">
<xe:this.databaseName><![CDATA[#{javascript:var serv:String = session.getCurrentDatabase().getServer();
serv + "!!" + "YOURDB.nsf";}]]></xe:this.databaseName>
</xe:dominoViewValuePicker>
</xe:this.dataProvider>
</xe:valuePicker>
I don't think you can have both dojo types. But with extlib.dijit.pickerlistsearch, double-clicking selects entries and does allow multiple to be selected. See http://www.intec.co.uk/extension-library-value-picker-and-extlib-dijit-pickerlistsearch/

How can I store a dynamic text value in selenium ide and use it later in different window

I am new in selenium and trying to learning. I am creating a script and I got stuck here, I want to store a dynamic value from text message on web page ex. " Event Name:Test" this Event Name is dynamic and I want to store this and want to get in other window. In 2nd window i want to use this value(Test) to verify in the page
I tried storeValue, StoreText and storeAttribute command and getting error message for xpath or "element not found".
Please help me and advice me , what should I do?
Can You please suggest me the Xpath for storing and retrieving the event name. Please help me...
Thanks in advance,
Niru
If you are using the same test-case to navigate from page 1 to page 2 you can use the storeText function in the IDE to store the value of your event name. And then you can use the same variable in the page 2 for verification.
For example, in page 1 to store the value of event you use:
storeText(locator1, temp)
And then on page 2 you use assert:
assertText(locator2, ${temp})