0
xPathを使用して「はい」チェックボックスをクリックしようとしていますが、わかりません。私は試しましたラベルのテキストに基づいてチェックボックスをクリックする方法
driver.find_element_by_xpath(".//label[following-sibling::input[contains(., 'Yes')]]").click() .
これは動作しませんでした。 過去に私がテキストフィールドを見つけるために
driver.find_element_by_xpath("//input[@id=(//label[text()=\"Phone Number\"]/@for)]")
を使用しているが、私は、チェックボックスのために同じことを行うことができませんでした。 ご協力いただければ幸いです。今、私は「はい」と言うチェックを見つける方法を考え出したことを、どのように私は "選択することができるであろう
<label for="responses_2865807_4737821">
<input id="responses_2865807_4737821" name="responses[2865807][]" type="checkbox" value="4737821">
"
Yes
"
</label>
:私の主な焦点は、次のコードでYESチェックしている
<dl data-validation="{"checkboxes":
{"required":true,"and":
[{"name":"checkboxes","operator":"checkboxes","options":{"message":"must select a value"}}]}}" class="form">
<dt><div class="form_response_label required" id="responses_2865807_label">Are you an Undergraduate Student?</div></dt>
<input id="responses_2865807_" name="responses[2865807][]" type="hidden">
<div class="form-checkbox">
<label for="responses_2865807_4737821">
<input id="responses_2865807_4737821" name="responses[2865807][]" type="checkbox" value="4737821">
Yes
</label> </div>
<div class="form-checkbox">
<label for="responses_2865807_4737822">
<input id="responses_2865807_4737822" name="responses[2865807][]" type="checkbox" value="4737822">
No
</label> </div>
<small><span class="right char_count"></span></small><div class="form-constraints"><div class="validation-summary" style="display: none;"><strong>Validation</strong><div class="explanation">Valid input may include: must select a value</div></div></div></dl>
質問に応じて「はい」と「いいえ」の間で変更する必要がある場合に備えて、その前に来たラベルを指定する「はい」ですか? 上記の例のコードでは、「あなたは大学生ですか?」というラベルの「はい」チェックボックスを探しています。
これは、 "//入力[contains(。、 'Yes')]" 'と同じくらい簡単にする必要があります。 – JeffC
うんうん、元々それを試しましたが、何らかの理由でそれが動作していませんでしたが、 '// label/input [contains(..、 'Yes')]'というトリックは完璧でした! – Jake