I am trying to automate a web page which has about 50 select buttons and here's an example
<input type="button" value="اختر" onclick="javascript:__doPostBack('ctl00$ContentPlaceHolder1$GridView1','Select$2')">
The part which is 'Select$2' is what changes from a button to another .. How can I specify the xpath of such a button?
I could select all the buttons using this
//input[#type='button']
But I would like to select specific button.
If you want to use unique part of onclick attribute as locator try
//input[#type='button' and contains(#onclick, 'Select$2')]
Related
I was using selenium with VBA and there is the current webpage. I was trying to get the bot to select the "exportbutton" ID, but I have already tried Findelementbyxpath etc., and the error is always returned saying it cannot locate that ID. It looks like the button is behind multiple divs and I am not sure how to select it. I have already looked through for iframes and there are none present in the webpage. How can I select this button behind this header.
Button Snapshot:
The <button> element have the id, class and tittle attributes.
<button id="exportbtn" class="button2" title="Save the report in a file (pdf, excel, ...)">
Solution
To click on the element you can use either of the following locator strategies:
Using FindElementByCss:
d.FindElementByCss("button#exportbtn[title='Save the report in a file (pdf, excel, ...)'] > span").click
Using FindElementByXPath:
d.FindElementByXPath("//button[#id='exportbtn' and #title='Save the report in a file (pdf, excel, ...)']/span").click
I am trying to automate a webpage to upload some data and there is a button which has HTML like that
<input type="file" class="upfile" name="upfile" id="upfile" style="height:auto;width:250px;" onclick="hideWarning(upfileWarning);hideWarning(pdfWarning);hideWarning(sizeWarning);">
When I tried this line
.ExecuteScript "document.getElementById('upfile').click();"
It didn't trigger the dialog box that is supposed to be populated. Any ideas?
To automate a datepicker, I tried using element.setvalue("12/12/2021")
Has anyone tried the datepicker by clicking on the dates on the modal using javascript? Do you start selecting the year and then click on the arrows for month?
The datepicker has an input element which you can fill text on. This is my code:
Actions actions = new Actions(driver);
actions.moveToElement(element);
actions.click();
actions.sendKeys(pickupDateTime);
actions.build().perform();
And then sendKeys "Enter" to close datePicker.
inputElement.sendkeys(Keys.ENTER);
Dojo newbie here and I have a dialog and before I dialog.show(), I want to fully set and select one of the text boxes. The select() is not available as I have tried. As an extension I need to select the entire textbox contents on any click in any textbox after the dialog is up. I cannot seem to get around the missing select(). How do I do it?
There's a selectOnClick attribute on TextBox that should help you out there:
<input data-dojo-type="dijit/form/TextBox"
data-dojo-props="selectOnClick:true"
value="Everything is selected on click"/>
http://jsfiddle.net/inanutshellus/v97wgxLb/
If you want to programmatically set focus and set the selection, you could cheat and call the private _onFocus method directly. Looks like you'd pass in the string "mouse", e.g.
myTextBox._onFocus("mouse");
Does anyone have any examples of a calendar popup that can be triggered using a ribbon button on a form?
I'm looking to have a popup where the user can select a date from the calendar which will then pass the value back to the javascript that launched it. I've seen that this can be done from a html popup but my efforts to create this so far haven't really been successful, so was hoping someone could advise me on the best solution.
Thanks
I've managed to find a good calendar that I have used for this solution. It can be found at https://github.com/dbushell/Pikaday
With this I put it into a html popup that had a text box on it (which would store the selected date) and had the javascript on my ribbon button show the popup.
The download includes the js files for the calendar to function and with a little tweaking of these you can make the calendar appear immediately on opening of the popup and not hide when a date is selected. Plus the text box can have its options changed so that it isn't visible to the user.
All put together this creates a rather pleasant looking calendar popup
You can use the date parameter type from html without using javascript
<input type=date >