<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
Related
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?
The number of select dropdowns in the page can vary, depending on the number of files a user chooses to upload to the website (from 1 up to 12 or so). So basically, find a required select dropdown, and then after making the proper selection, move on or scroll down to the next div with a required dropdown until all dropdowns have their proper selection made so that form submission can move forward.
<select class="form-control" id="dynamic-id" required="">
<option value="">[Choose Option]</option>
<option value="random_value">ALWAYS SELECT ME</option>
</select>
...
<select class="form-control" id="dynamic-id" required="">
<option value="">[Choose Option]</option>
<option value="random_value">ALWAYS SELECT ME</option>
</select>
I tried doing it like this
try:
required_dropdowns = driver.find_elements_by_xpath("//select[#required]/option")
print(len(required_dropdowns))
for each_dropdown in required_dropdowns:
required_dropdowns[1].click()
time.sleep(2)
except:
NoSuchElementException
print("Could not find required dropdown"):
time.sleep(2)
Output prints out 36 dropdowns but it selects the proper option only for the first one.
I would really appreciate any input on how to execute this.
Using Python WebDriver, how can I select a radio button based upon the text of a separate element such as this label?
My current code has the ability to click the radio button by id. But I have no idea how it is possible to click it when I am depending on text from a completely separate element.
The following is a pic of what i'm up against.
All help is greatly appreciated! =)
I've created a simplified example of your html on the screenshot, and assuming you want to get radio button which following sibling has "test text2", you need to use xpath axes:
<table>
<tbody>
<tr>
<td><input id="test_id" type="radio" value="123" /></td>
<td>test text</td>
<td>test text2</td>
<td>test text3</td>
</tr>
</tbody>
</table>
XPath would be: //tr/td[contains(text(),"test text2")]/preceding-sibling::td/input
The logic is:
get an element with specific text
go to previous sibling element (sibling == same level element)
now go deeper to td/input from there
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
I am not able to select the drop down option in the webpage using python selenium webdriver
Pasted the HTML code of those web elements,
<td class="CR">
<select onchange="wl_recalc();" name="wl_nmode">
<option value="-1">Auto</option>
<option value="0">Off</option>
</select>
</td>
This is the image of the dropdown option which i am not able to select, i am able to click the 802.11n mode as shown in the picture by finding element by name. but i am unuccessfull in setting the option to off by selecting the element using xpath