Starting automation at my job and currently the way I've been doing it by xpath and button description. There are only classes, no id's, and right now dev is re-doing the UI. Therefore, CSS selectors will probably not be reliable. However, going off the button description doesn't seem reliable either.

Is there a way to create an xpath or find an element using the client-side JS? Everything is written in Java and I'm using selenium.

I was trying to do something to this effect:


Is that possible or is there a better way than using the button description?

For example, this is what I'm dealing with:

     <div class="yui3-u nav-button">
       <div class="yui3-u-1 nav-content">
          <div class="yui3-u img-holder"></div>
            <div class="yui3-u nav-text">
  • It is webdriverjs you are using? Have you checked the API doc? – SayusiAndo Aug 13 '15 at 14:12
  • Try this link, it should help you developer.mozilla.org/en-US/docs/… – Dhiman Aug 13 '15 at 14:30
  • 1
    If developement changes the UI ask them to add IDs to the elements for improving testing (and location errors) a lot! – bish Aug 13 '15 at 14:51
  • Generally if they're redoing the UI then nothing is going to be reliable. The best you can do is to make your selectors as generic as possible. CSS selectors are generally the most robust because xpaths can have flakey support cough IE cough. CSS selectors should give you plenty of flexibility because it's easy to have them include attributes like class names and IDs if they exist. – Julian Aug 13 '15 at 17:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.