1
この場合、選択したオプション名:Option3を取得したいので問題があります。この場合、値が正しく選択されているかどうかを確認するためにassertを使用したいと思います。あなたは以下の私のページの一部を見ることができます:選択したオプションを取得する方法(Selenium&Python)
<html>
\t <body>
\t \t <table border="0" cellpadding="0" cellspacing="0" class="rich-toolbar " id="mainMenuToolbar" width="100%">
\t \t \t <tbody>
\t \t \t \t <tr valign="middle">
\t \t \t \t \t <td class="rich-toolbar-item " style=";">
\t \t \t \t \t \t <form id="substituteForm" name="name" method="post" action="http://homepage/home.seam" enctype="application/x-www-form-urlencoded">
\t \t \t \t \t \t \t <select name="substituteForm:j_id158" size="1" onchange="document.getElementById('substituteForm:substituteSubmit').click();">
\t \t \t \t \t \t \t \t <option value="0">Option0</option>
\t \t \t \t \t \t \t \t <option value="1">Option2</option>
\t \t \t \t \t \t \t \t <option value="2" selected="selected">Option3</option>
\t \t \t \t \t \t \t </select>
\t \t \t \t \t \t </form>
\t \t \t \t \t </td>
\t \t \t \t </tr>
\t \t \t </tbody>
\t \t </table>
\t </body>
</html>
私はXPathをコピーするためにDevToolを使用して、私はコードを書いた:
element = Select(driver.find_element_by_xpath("//* [@id='substituteForm']/select"))
と、私はエラーメッセージを持っている:
をselenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: //*[@id='substituteForm']/select
多くのXPathの組み合わせを試しましたが、それでも動作しません。
ヤップ。それは今働く。ありがとう:) – Surion