I have been trying to enter a website using Python and it's Selenium Package. In this website I have to: (1) enter some login credentials (2) go to a specific page (need the credentials to travel there) (3) select value from drop-down list
I have managed the first two steps, however, I can't manage to overcome the drop-down list problem. I always get the error:
Message: invalid argument: Unsupported locator strategy: null
I have tried to change my Locator method from "name" to "id" and to "value" but have been unsuccessful.
Any assistance would be much appreciated, I am puzzled as to why all the rest works and this specific point fails. I can't provide the original website as example due to proprietary issues.
Thank you!
EDIT: I have added the HTML code regarding the drop-down list, had to omit some information due to personal details but I think it should help anyways.
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support.ui import Select
#log-in info
userStr = "User"
passStr = 'Pass'
#enter log-in
browser = webdriver.Chrome()
browser.get(('https://www.example.com'))
Log_User = browser.find_element_by_id('user_field')
Log_User.send_keys(userStr)
Log_User = browser.find_element_by_id('pass_field')
Log_User.send_keys(passStr)
Enter_Button = browser.find_element_by_id('enter_button')
Enter_Button.click()
#go to desired window
browser.get(('https://www.example.com/newpage.aspx'))
#select dropdown (the issue is here)
select = Select(browser.find_element_by_name('drop-down-list'))
select.select_by_value("target")
<div class="ms-webpart-zone ms-fullWidth">
<div id="MSOZoneCell_WebPartWPQ2" class="s4-wpcell-plain ms-webpartzone-cell ms-webpart-cell-vertical ms-fullWidth ">
<div class="ms-webpart-chrome ms-webpart-chrome-vertical ms-webpart-chrome-fullWidth ">
<div webpartid="46ca13d8-6d03-474f-bc6c-d2c6cf8c95f2" haspers="false" id="WebPartWPQ2" width="100%" class="ms-WPBody noindex " allowdelete="false" style=""><div class="ms-rtestate-field"><h2 class="3s-web-title">***<br></h2></div><div class="ms-clear"></div></div>
</div><div class="ms-PartSpacingVertical"></div>
</div><div id="MSOZoneCell_WebPartctl00_ctl51_g_0c672ab8_73ff_4b46_a925_3f0c0213b64d" class="s4-wpcell-plain ms-webpartzone-cell ms-webpart-cell-vertical ms-fullWidth ">
<div class="ms-webpart-chrome ms-webpart-chrome-vertical ms-webpart-chrome-fullWidth ">
<div webpartid="0c672ab8-73ff-4b46-a925-3f0c0213b64d" haspers="false" id="WebPartctl00_ctl51_g_0c672ab8_73ff_4b46_a925_3f0c0213b64d" width="100%" class="ms-WPBody noindex " allowdelete="false" style=""><div style="display: table; margin-bottom: 10px;"><div style="display: table-row;"><div style="display: table-cell; vertical-align: middle; text-align: left;"><label style="margin-bottom: 0px;" for="ctl00_ctl51_g_0c672ab8_73ff_4b46_a925_3f0c0213b64d_ddlDealers">Concessionário:</label></div><div style="display: table-cell; vertical-align: middle; text-align: left; padding-left: 15px;">
<select name="ctl00$ctl51$g_0c672ab8_73ff_4b46_a925_3f0c0213b64d$ddlDealers" onchange="javascript:setTimeout('__doPostBack(\'ctl00$ctl51$g_0c672ab8_73ff_4b46_a925_3f0c0213b64d$ddlDealers\',\'\')', 0)" id="ctl00_ctl51_g_0c672ab8_73ff_4b46_a925_3f0c0213b64d_ddlDealers">
<option selected="selected" value="-1;-1">-- Concessionário --</option>
<option value="*****;****">***** (Special Sales) (****2)</option>
...
</select></div></div></div>
<span>Necessita de seleccionar um concessionário.</span><div class="ms-clear"></div></div>
</div>
</div>
</div>