Перед поиском элементов, пожалуйста, попробуйте использовать инструменты разработчика F12, чтобы проверить, можете ли вы найти элементы из ресурса страницы? правильное имя класса или значение идентификатора? И проверьте, используете ли вы Iframe или нет?
Если тег iframe не используется , то вы можете обратиться к следующему примеру кода, чтобы найти элементы (из вашего кода кажется, чтоэлемент представляет собой выпадающий список, я полагаю, вы хотите выбрать параметры).
import time
from selenium import webdriver
driver = webdriver.Ie("D:\\Downloads\\webdriver\\IEDriverServer_x64_3.14.0\\IEDriverServer.exe")
# connect to the specific ip address
driver.get("<the website url>")
#print("prompt sample")
#find element by id
#driver.find_element_by_id('Text1').send_keys("hello world")
#find element by xpath
driver.find_element_by_xpath("//input[@id='Text1']").send_keys("hi")
#execute the javascript function and set the input text value.
#driver.execute_script("document.getElementById('Text1').value = 'Hi';")
#find element by xpath and using the id attribute.
driver.find_element_by_xpath("//select[@id='ctl00_PlaceHolderMain_CreatePerson_uoc_BasicInfo_grouping_UserType_control_internalDropDownList']/option[text()='Open']").click()
#find element by xpath and using the class attribute.
driver.find_element_by_xpath("//select[@class='ddl_internalDropDownList_cs']/option[text()='In Progress']").click()
Результат, как показано ниже:
![enter image description here](https://i.stack.imgur.com/7iEbk.png)
Ресурс веб-страницы выглядит следующим образом:
<input id="Text1" type="text" value="" />
<select id="ctl00_PlaceHolderMain_CreatePerson_uoc_BasicInfo_grouping_UserType_control_internalDropDownList">
<option value="">-- None --</option>
<option value="1">Pending</option>
<option value="2">Queued</option>
<option value="3">Open</option>
<option value="4">In Progress</option>
<option value="5">Cancelled</option>
<option value="6">Closed Complete</option>
</select>
<select id="ddl_internalDropDownList" class="ddl_internalDropDownList_cs">
<option value="">-- None --</option>
<option value="1">Pending</option>
<option value="2">Queued</option>
<option value="3">Open</option>
<option value="4">In Progress</option>
<option value="5">Cancelled</option>
<option value="6">Closed Complete</option>
</select>
Если элемент расположен в теге iframe , сначала мы должны найти элемент iframe и переключиться на iframe, а затем найтиэлементы внутри него.
Вы можете обратиться к следующему примеру кода:
import time
from selenium import webdriver
driver = webdriver.Ie("D:\\Downloads\\webdriver\\IEDriverServer_x64_3.14.0\\IEDriverServer.exe")
# connect to the specific ip address
driver.get("<the website url>")
#print("prompt sample")
#find the iframe tag and switch to the frame
iframe = driver.find_elements_by_tag_name('iframe')[0]
driver.switch_to_frame(iframe)
#driver.find_element_by_id('Text1').send_keys("hello world")
driver.find_element_by_xpath("//input[@id='Text1']").send_keys("hi")
#execute the javascript function and set the input text value.
#driver.execute_script("document.getElementById('Text1').value = 'Hi';")
driver.find_element_by_xpath("//select[@id='ctl00_PlaceHolderMain_CreatePerson_uoc_BasicInfo_grouping_UserType_control_internalDropDownList']/option[text()='Open']").click()
driver.find_element_by_xpath("//select[@class='ddl_internalDropDownList_cs']/option[text()='In Progress']").click()
# move out of iframe
driver.switch_to_default_content()
Результат, как показано ниже:
![enter image description here](https://i.stack.imgur.com/1LbTv.png)