Now I want to print all the date like "03/17/2018" in Selenium WebDriver, and here is my HTML inspect in Chrome:
<div id="ember3175" class="ember-view encounter-list"><header class="box-margin-Bsm"><h3 class="header3a">Encounters</h3></header>
<section class="d-complex-list-container box-padding-Tsm-v2 type-v2">
<div class="item box-padding-TBxs-v2">
<span class="link-text box-margin-Rsm-v2">03/17/2018</span>
<span>Encounter (Patient Phone Message)</span>
<!----> <div class="chief-complaint">
<span class="p-666">CC:</span>
<span>Pt. called to follow-up on monospot results.</span>
</div>
</div>
<div class="item box-padding-TBxs-v2">
<span class="link-text box-margin-Rsm-v2">02/17/2018</span>
<span>Encounter (SOAP Note)</span>
<!----> <div class="chief-complaint">
<span class="p-666">CC:</span>
<span>chronic sinusitis</span>
</div>
</div>
<div class="item box-padding-TBxs-v2">
<span class="link-text box-margin-Rsm-v2">01/17/2018</span>
<span>Encounter (SOAP Note)</span>
<!----> <div class="chief-complaint">
<span class="p-666">CC:</span>
<span>nasal congestion</span>
</div>
</div>
<div class="item box-padding-TBxs-v2">
<span class="link-text box-margin-Rsm-v2">11/17/2017</span>
<span>Encounter (SOAP Note)</span>
<!----> <div class="chief-complaint">
<span class="p-666">CC:</span>
<span>nasal congestion</span>
</div>
</div>
<div class="item box-padding-TBxs-v2">
<span class="link-text box-margin-Rsm-v2">10/17/2016</span>
<span>Encounter (SOAP Note)</span>
<span class="link-text icon-lock"></span>
<div class="chief-complaint">
<span class="p-666">CC:</span>
<span>nasal congestion</span>
</div>
</div>
<!----></section>
</div>
Now I can print any single date with its XPath as:
String time = driver.findElement(By.xpath("//*[@id=\"ember3175\"]/section/div[2]/span[1]")).getText();
System.out.println(time);
But I want to iterator all the date and print all the date, I tried:
int size = driver.findElement(By.xpath("[@id=\"ember3175\"]/section/div/span[1]")).size();
To get the size of all the children element, but there is an error that I cannot get its size. So my question is how I iterate and print all the dates here? Also, If I want to do iterative jobs in other tables, how can I choose the parent? I mean most time I could get any single data with its XPath in Chrome, but when I want to iterate all the data, I do not know how to choose the parent and get its size. Thank you very much!