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?
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
<input type="radio" name="isLayoutApprov" value="Y"> 1.Approved
<input type="radio" name="isLayoutApprov" value="N">2.UnApproved
How we can write code for the above html in Python selenium?
Here type and name are the same, the only difference is value in this page another radio button with same values
driver.find_element_by_css("input[value='Y'][name='isLayoutApprov']").click()
to click on Approved
or
driver.find_element_by_css("input[value='N'][name='isLayoutApprov']").click()
to click on UnApproved
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')]
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);
I want to select a value from a dropdown list and submit the selected value in mlab database.
Currently, I'm able to display all the data in the dropdown but I'm not able to select a value it just shows the "Select..." text on the button even after I select the value from the list. I'm not sure if I'm missing anything (ngModel or formControlName) - I would like to select the value from the list and then save it to the db.
Also, I have connected everything to the db as I'm able to save other input fields except this dropdown one.
Code:
<div class="dropdown">
<button class="btn btn-primary btn-sm dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Select...
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a class="dropdown-item" *ngFor="let user of users" attr.data-value={{user._id}} id="person">{{ user.username }}</a>
</div>
</div>
Any help is appreciated!
I would us a select for this and do an ngFor for the options. As for submitting the data, you can use either template forms or Reactive Forms. The difference is you would use ngModel for the template forms and FormGroups for reactive forms. Then you would submit either the model or the form group to your service. If you want to not use a select, I think you can add a property in the .ts file and set the button text to that property. Then add a click event to the a tag where you update the property based on the clicked item. Hope this helps