Search code examples
selenium-webdriverdynamic-text

Dynamic Text in selenium Webdriver


I m automating a web application and need help at one point.

When even i login to the web app. it ask for the user name(manager id) and then that manager id keep on flashing on home page. Manager id changes with different login credentials.

So i need to keep checking that Manager id.

<tr>
<td>
<center>
<table width="100%" align="center">
<tbody>
<tr/>
<!--comments: To link all the screens-->
<tr>
<tr class="heading3" align="center">

<td style="color: green">Manger Id : mngr8499</td>

</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</body>

The manager ID as you can see in DOM is displayed as Manager Id: XXXX

So please help me how to locate these "XXXX" only, out of Manager id: XXXX


Solution

  • To my understanding after using getText() you get Manger Id : mngr8499 but you do not want every time Manager ID with the text and only ID. My Implementation would be to first copy the text in the any String variable and then using String.replaceAll() Method i can get the required text.

    Below is the implementation of the same, Please let me know in-case if i am understanding the question wrong.

    WebElement mngrid = driver.findElement(By.xpath("//tr[@class='heading3']/td"));
    String actual_text = mngrid.getText();
    actual_text= actual_text.replace("Manger Id :"," ");
    System.out.println(actual_text);