5

以下のラベルの xpath を試していますが、要素を見つけることができません。

driver.findElement(By.xpath("//div[label[contains(text(),'Patient's Name']]")).isEnabled();

XPath: .//*[@id='update_patient_profile']/div/div[1]/label --- FirePath から取得。

以下は、フィールドの HTML ソースです。

<form id="update_patient_profile" action="/subscriber/" method="post" name="update_patient_profile"> 
  <div class="subscriberAddPatient"> 
    <div class="formData nameInputs"> 
  <label for="first_name">Patient's Name</label>
  <input id="first_name" class="left nameRule" type="text" onblur="resetTxtAdd($(this))" onfocus="emptyFieldAdd($(this))" onclick="emptyFieldAdd($(this))" name="first_name" value="First Name" maxlength="24"/>

誰でも、ラベルの正しい XPath を提案できますか?

4

3 に答える 3

5

以下のXPATHを使用する必要があります

 //*[@id='update_patient_profile']//div[2]/label[.='Patient's Name']
于 2013-09-24T19:38:57.130 に答える
1

ドット"."の代わりにtext()を使用することもでき ます。. ラベルのテキストを確認するには、このパスも使用できます

//form[@id='update_patient_profile']//div[2]/label[text()='Patient's Name']
于 2015-10-23T12:20:17.417 に答える
1

//form[@id='update_patient_profile']/label[text()='Patient's Name']

labelタグは form タグの子でもあるため。

于 2017-12-01T10:22:23.520 に答える