0

I am working with a dynamic website, ID is available with dynamic guid. Could any one explain me how can I write manual xpath to find an element in the website?

   <input id="JointInsureds_1e124dce-7492-4315-b1d8-7b806babd994__ForeName" 
        type="text" 
        value="" name="JointInsureds[1e124dce-7492-4315-b1d8-7b806babd994].ForeName"   
        maxlength="20"
        data-val-required="The First Name field is required." 
        data-val-length-max="20" 
        data-val-length="The field First Name must be a string with a maximum length of 20." 
        data-val="true"/>
Carl Witthoft
  • 19,580
  • 8
  • 40
  • 67

1 Answers1

1

With CSS, you can use:

input[id^='JointInsureds'][$='ForeName']

In CSS, you can handle dynamic elements using:

*=  - contains
^=  - starts with
$=  - ends with
~=  - contains (space seperated)

With XPath, you can use:

//input[starts-with(@id, 'JointInsureds')][ends-with(@id, 'ForeName')]

(don't quote me on the xpath, it might need some revision. it's been years since i've used it because css is perfectly capable for tasks like this)

ddavison
  • 25,442
  • 12
  • 70
  • 96