Reputation: 1
I have tried to locate button in my web app using xpath but it changes automatically each time I open selenium IDE. Is there any other way to locate it except using xpath or position? can I locate it using class name? If yes then how can I do it?
Upvotes: 0
Views: 647
Reputation: 298
Use a CSS selector. This site really helped me: http://saucelabs.com/resources/selenium/css-selectors
if it has an id on it you can just say "id=yourid"
for css it could be something like this: "css=button[class*='yourclass']" <-- that says it's a button, and that in class it contains yourclass.
Upvotes: 0
Reputation: 1
Answer - If by default recorded xpath are not working for your application, then you can define your own xpath for those components which should remain same throughout execution.
Please refer below URL which shows ways to develop userdefined xpath :-
http://docs.seleniumhq.org/docs/appendix_locating_techniques.jsp
Upvotes: 0
Reputation: 19516
Since it is your webapp, consider adding an id
or a name
to uniquely identify the element. It also makes the xpaths easier to write as you don't need to consider the possibility where you might be grabbing too many elements.
Upvotes: 0
Reputation: 1805
You can use xpath to find element by class name.
//*[@class='someClass']
where, someClass
is the class name of your element.
Upvotes: 1