ltp61992
ltp61992

Reputation: 19

Using Selenium IDE to find dynamic ID

I have been able to locate the element by using the following command, target and Value.

Command:  Select
Target:   //div[@id='ui-id-51']/div[2]/div/fieldset/div/div/select
Value:    Documentation 

This xpath works, however, the id number is dynamic and will change each time that I open up this window a new time. So the number (51 in this example) may be 201 the next time that I open this window, but the ui-id- will always be the same. So this Target is not found the next time I open the window. I have tried using the following xpath to fix this, but it does not work.

Command:   Select
Target:    //div[starts-with(@id,'ui-id-')]/div[2]/div/fieldset/div/div/select
Value:     Documentation

Can someone give me the correct xpath to find this target with a dynamic id?

Here is the HTML:

<div id="ui-id-22" class="ui-dialog-content ui-widget-content" style="display: block; width: auto; min-height: 0px; max-height: none; height: 552px;">

    <div></div>
    <div class="patient-module-contact-edit">
        <!--

         start of template: "#contact_log_logEntry_edit" 

        -->
        <div class="new-encounter">
            <fieldset class="wide-mode liquid" style="border: none; padding-top: 0px;">
                <div class="row span5">
                    <div class="span5">
                        <label></label>
                        <select class="encounterType vf vf-required span4 vf-validated" name="encounterType" style="visibility: visible; background-color: rgb(238, 238, 238);">
                            <option value=""></option>
                            <option value="INBOUND_TELEPHONE"></option>
                            <option value="OUTBOUND_TELEPHONE"></option>
                            <option value="OUTBOUND_TELEPHONE_VM"></option>
                            <option value="OUTBOUND_TELEPHONE_NO"></option>
                            <option value="INBOUND_EMAIL"></option>
                            <option value="OUTBOUND_EMAIL"></option>
                            <option value="INBOUND_FAX"></option>
                            <option value="OUTBOUND_FAX"></option>
                            <option value="INBOUND_TEXT"></option>
                            <option value="OUTBOUND_TEXT"></option>
                            <option selected="" value="ENCOUNTER"></option>
                            <option value="DOCUMENTATION"></option>

Upvotes: 1

Views: 5740

Answers (1)

alecxe
alecxe

Reputation: 473863

starts-with() based solution looks good and should work according to what you've provided.

You can also try a bit broader check using contains():

//div[contains(@id,'ui-id-')]/div[2]/div/fieldset/div/div/select 

Upvotes: 1

Related Questions