cancel
Showing results for 
Search instead for 
Did you mean: 

using tag in FindBy annotation

rezza
Occasional Contributor

using tag in FindBy annotation

Hi

I've created a complete test case using the cucumber and everything is fine.

I've used the XPath for targeting the elements.

And using the XPath was a little messy.

I want to add a new property in all the elements for making it easier to targeting elements.
Should I add the "tag" property in elements?

And also for using that, Should I use the "tagName" in the @FindBy?

If so, what name would you suggest for the tag property?

Something like "ui_testing_button" is good?

4 REPLIES 4
rezza
Occasional Contributor

Re: using tag in FindBy annotation

there is no solution?

aslakhellesoy
Moderator

Re: using tag in FindBy annotation

While Cucumber works well with Selenium WebDriver, we don't offer technical support for Selenium WebDriver. Please ask in their forums.

------
I'm the creator and lead developer of Cucumber Open.
rezza
Occasional Contributor

Re: using tag in FindBy annotation

@aslakhellesoy 
Sorry I didn't get it exactly.
Shouldn't I use the selenium WebDriver?
What should I do?

Re: using tag in FindBy annotation

I suggest to use HTML data attributes for that purpose: https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes

 

It is good practice to use `data-test-*` for test related custom data attributes.

 

As selenium does not provide dedicated methods to work with data attributes, it is possible to retrieve those easily with standard css query selectors like `By.cssSelector("[data-test-id: \"my-unique-test-id\"]")` as see here: https://sqa.stackexchange.com/questions/39202/selenium-locate-elements-via-custom-attribute

New Here?
Join us and watch the welcome video: