Is there any way to identify textbox from its inner text?

Is there any way to identify textbox from its inner text? kindly check attached image for clear idea 

Is there any way to identify textbox from its inner text?

Train Asked on July 7, 2016 in Selenium WebDriver.
Add Comment
  • 3 Answer(s)

    Hi John,

    Html elements have attributes

    in belowe html snippet input is tag
    and all highligted are called as attributes
    <input  id=”from_typeahead1 class=”typeahead1 input-md form-control tt-input tabindex=”4 onkeypress=”javascript:checkSpecialCharacters(event); placeholder=”Type Departure City autocomplete=”off spellcheck=”false style=”position: relative; vertical-align: top; dir=”auto>

    you can use any attribues with tag name to create xpath
    like in your case you can create xpath as
    //input[@placeholder=’Type Departure City‘]
    other attributes can also be used to create xpath like
    //input[@dir=’auto‘]
    //input[@spellcheck=’false’].
    i hope your doubt is clear now.

    Regards
    Ankit

    Vice Professor Answered on July 7, 2016.
    Add Comment

    Ankit Thanks  for reply,

    here i want to sendkeys to textbox by finding it through inner text
    for example, if you check http://www.akbartravels.com/ there is also textbox asking Type Departure Location here, so i want to write common script for different url and detect textbox and execute my script, can this be done using selenium webdriver?

    once again thanks for helping!!

    Train Answered on July 7, 2016.

    Hi John
    You cannot write common script for them.
    Different UI developers use differnt kind of approaches to create Ui elements.
    like in case 1 the  text can be identified using
    //input[@placeholder=’Type Departure City‘]

    but in 2nd case there is no attribute like placeholder.
    so i think you need to write different code for both of these sites.

    on July 8, 2016.
    Add Comment

    thanks ankit, for help

    Train Answered on July 11, 2016.
    Add Comment
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.