Home > Blockchain >  CSS selector with in Selenium IDE records are different when copied from browser development tools
CSS selector with in Selenium IDE records are different when copied from browser development tools

Time:02-27

For some websites Selenium IDE will record a CSS selector in a different way than the one I get when you copy the selector from the developer tools. Here's an example page :

https://www.barnesandnoble.com/w/the-woman-they-could-not-silence-kate-moore/1138489968?ean=9781728242576

Price selector on Selenium IDE

id=pdp-cur-price

Price selector from dev tools

div.price-current-old-details:nth-child(3) > span:nth-child(1)

or

span#pdp-cur-price.price.current-price.ml-0

Add to cart button from IDE

css=.add-to-cart-button

Add to cart button from dev tools

form.focus > input:nth-child(5)

or

input.add-to-cart-button.btn-addtocart.btn-pdp-addtocart.btn.btn--commerce.mr-xs

This of course doesn't help when running the selenium script.

What solutions worked for you in getting accurate CSS selectors?

CodePudding user response:

The locators you get by IDE are correct while automatically generated locators from the dev tools are far from being so effective.
I advice you to learn how to create correct and effective locators.
There are many tutorials describing that, for example these

CodePudding user response:

Despite the fact Selenium IDE and Developer Tools suggests near perfect locator strategies, it is always advisable to formulate more canonical locator strategies tweaking the element attributes, so the desired WebElements are uniquely identified within the DOM Tree.

You can find a couple of relevant detailed discussions in:

  • Related