Question

How to get the value of div tag under the label "Date of Joining" , i.e I need the value "06/06/2009" I can go upto the label with text "date of joining", but how to get the text of div under the tag Label". Following is html code -

<div class="employee_highlight" style="background-color: transparent;">
<ul class="employee_highlight_layout">
<li>
<li>
<li>
    <div class="column_left">
        <label for="Department" style="background-color: transparent;">Date of Joining</label>
    </div>
    <div class="column_right" nowrap="nowrap">06/06/2009</div>
</li>
<li>
</ul>
</div>
Was it helpful?

Solution

You can directly fetch the text this way:

String doj = driver.findElement(By.xpath("//li[contains(.,'Date of Joining')]//div[2]")).getText();

or

String doj = driver.findElement(By.xpath("//li[contains(.,'Date of Joining')]//div[@class='column_right']")).getText();

OTHER TIPS

You must have stored element for text 'Date of Joining', let's say it is element. Now, we can find the element with text '06/06/2009' with following:

element.findElement(By.xpath("..//following-sibling::div")).getText();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top