'CSS selector with in Selenium IDE records are different when copied from browser development tools

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?



Solution 1:[1]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Prophet