1

I need to verify whether placeholder/helper text is displayed for a field. In this example it is Min. $50.00 I don't see any placeholder/helper text attribute defined inside the div tags. My field looks like enter image description here . Displayed amount (in this example $50.00) is dynamic. Code for the above field looks like

<div  class="unit" style="padding-left:32px;">
        <input id="Amount" type="text" class="inputAlign optionalHintText" size="18" maxlength="30"/>
        <div id="sharesValueForPercent" class="TextMd"></div> 
</div>

I tried different ways to get the text (Min$50.00). Can someone help me on this. Appreciate your response.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
siri
  • 81
  • 2
  • 9

1 Answers1

1

To extract the placeholder text i.e. $50.00 you can use either of the following Locator Strategies:

  • Using cssSelector:

    System.out.println(driver.findElement(By.cssSelector("input.inputAlign.optionalHintText#Amount")).getAttribute("value"));
    
  • Using xpath:

    System.out.println(driver.findElement(By.xpath("//input[@class='inputAlign optionalHintText' and @id='Amount']")).getAttribute("value"));
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352