how to select the drop down option in webpage using selenium python? - python-3.x

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

Related

Select radio button using Selenium

<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

Send Tab button key press event 10 times and increment it by 1 in a loop

Is there a way where I can send a TAB key press event 10 times using the command (Application.SendKeys "{TAB 90}) and then programmatically increment the count by 1 such that it sends (Application.SendKeys "{DOWN 91}) .
I have a drop down list on a web page where I need to select an item, press a search button ,then scraps items from the resulting searched page and finally going back to the main search page to again select the next item in the drop down list to repeat the above process. The drop down list contain 300 items.
I know there might be a better way to do this. Please enlighten me.
Below is the HTML snippet from the web page containing the details:-
<td style="width: 100%;">
<select name="filter1.F1" tabindex="5" id="filter1.F1" onkeydown="dataExplorerDropDownKeyPress(event)" dataexplorerdropdownstate="Collapsed" dataexplorerdatatype="TABLE">
<option name=""></option><option value="aaa_0">000</option>
<option value="aaa_1">ABC</option>
<option value="aaa_2">BCD</option>
.
.

How do you use Selenium Python and have it go through every select tag that is REQUIRED in a web page, and then always choose [1] or the first option?

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.

Python Webdriver - How can I select a radio button based upon the text of a separate label?

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

Selecting a dropdown option with no attributes with WATIR

I am having trouble selecting this with watir. I'm trying xpath and is able to try something like this
browser.element_by_xpath("select/option[2]").text
and it will return the text. but how would i select the text in the dropdown. Thanks
<select>
<option value="">--Select One--</option>
<option value="test">NAME1</option>
<option value="test2">NAME2</option>
</select>
Found out how to do it myself. Here is what i did for reference.
browser.select_list(:xpath, "select/option[2]").set(browser.select_list(:xpath, "select/option[2]").getAllContents[2])

Resources