選択フィールドからSelenium & Pythonを使用してオプションを選択したいとします。SeleniumとPythonを使用してドロップダウンから値を選択する方法
次のようにHTMLは次のとおりです。
<select autocomplete="off" class="style_input_item" name="AccountEnable" id="Enable" value="0" onchange="onPageDataChange()">
<option value="0" selected="selected"><script>T("Disabled")</script>Disabled</option>
<option value="1"><script>T("Enabled")</script>Enabled</option>
</select>
を、次のように私が試した:
driver.find_element_by_xpath('//*[@id="Enable"]/option[value="1"]').click()
私はそのエラーを受け取りました:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="Enable"]/option[value="0"]"}
[セレン - パイソン - ドロップダウンメニューのオプション値]の可能性のある重複します(http:// selectoverflow.com/questions/7867537/selenium-python-drop-down-menu-option-value)。受け入れられた答えは最良の方法ではありません。最良の方法は、アレクセの答えです。 http://sqa.stackexchange.com/questions/1355/what-is-the-correct-way-to-select-an-option-using-seleniums-python-webdriverも参照してください。 – JeffC
受け入れられた答えは最善の方法ではありません。最良の方法は、アレクセの答えです。 http://sqa.stackexchange.com/questions/1355/what-is-the-correct-way-to-select-an-option-using-seleniums-python-webdriverも参照してください。 – JeffC