[英]Can't click to dropdown element. Selenium, Python
我的任務是 ckoose 下拉元素之一。
我的 HTML 是:
<td>
<select name="subtract">
<option selected="selected" value="1">Да</option>
<option value="0">Нет</option>
</select>
</td>
我的代碼是:
>>>selectbox = ff.find_element_by_name("subtract")
>>>print (selectbox.text)
Да
Нет
>>>print(Select(selectbox).options)
[<selenium.webdriver.remote.webelement.WebElement object at 0x00000000037992E8>, <selenium.webdriver.remote.webelement.WebElement object at 0x0000000003799278>]
>>>print(Select(selectbox).select_by_index(0))
None
>>>print(Select(selectbox).select_by_value('0'))
None
>>>print(Select(selectbox).select_by_visible_text('Нет'))
None
所以我真的找不到我錯在哪里?
我不確定Select
。 但是試試這個代碼:
find_element_by_xpath("//select[@name='subtract']/option[@value='0']").click()
或這個
find_element_by_xpath("//select[@name='subtract']/option[@value='1']").click()
編輯:或嘗試使用 xpath Select
:
Select(driver.find_element_by_xpath("//select[@name='subtract']").select_by_value('0')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.