I am in the process of creating a function that allows the user to interface with a website via Python. Specifically, the user will be provided with a list of options to select, and the selected option will click on the corresponding link. Let's assume this is my code:
crop = input('\n\nSelect a crop: Wheat, Wetland rice, Dryland rice, Maize, Barley, Sorghum, Rye, Pearl millet, '
'Foxtail millet, Oat, Buckwheat, White potato, Sweet potato, Cassava, \n Yam and Cocoyam, Sugarcane, Sugarbeet,'
' Phaseolus bean, Chickpea, Cowpea, Dry pea, Gram, Pigeonpea, Soybean, Sunflower, Rapeseed, Groundnut, Oilpalm, '
'Olive, Jatropha, \n Cabbage, Carrot, Onion, Tomato, Banana, Citrus, Coconut, Cocoa, Cotton, Flax, Coffee, Tea, '
'Tobacco, Alfalfa, Pasture, Miscanthus, Switchgrass, Reed canary grass')
<input id="buttonSubmit__dim_fieldcrp2=ce_whe&dimType=crp2&fieldmain=main_py_six_qdns&idPS=1e1d6e7d7ec3368cf13a68fc523d1ed4870e8b45&idAS=0&idFS=0" name="fieldcrp2=ce_whe&dimType=crp2&fieldmain=main_py_six_qdns&idPS=1e1d6e7d7ec3368cf13a68fc523d1ed4870e8b45&idAS=0&idFS=0&_passChanged=true&_eventdim" value="Wheat" onclick="return wf_click(this);" type="submit" class="linksubmit linksubmitfalse" style="border: none;">
I guess you can select your
input element with the
find_element_by_css_selector method. As it's allowed by css selectors you can access the attributes of your elements, so in your example for an
input element with
elem = driver.find_element_by_css_selector("input[value=\"Wheat\"]") elem.click()
If you have many
input elements with that value you can try to be more precise by previously selecting the parent element of the
input you are targeting or by adding the class name of you element in the css selector:
elem = driver.find_element_by_css_selector("input.linksubmit[value=\"Wheat\"]") elem.click()
To use the value entered by the user you can use the
format method of your string:
Edit: For the record, the
Select(...) selenium class is used to models an element with the
select html tag, allowing you afterwards to
select_by_value one of it's
option for example.