Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Unable to get element error using Selenium in Python

This is a weird one, I am trying to get product names and price from a website using selenium in Python. I am able to get the price but getting the unable to locate element error for product name.

enter image description here
Website Link

I am using very similar code for both these items :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

s3 = driver.find_element(By.CSS_SELECTOR, "span.weight-tile__PriceText-otzu8j-5.hJFddt")

print(s3.text)

s = driver.find_element(By.CSS_SELECTOR, "span.mobile-product-list-item__ProductName-zxgt1n-6.hBmGOx")

print(s.text)

>Solution :

css selector is trying to find the class which is valid for mobile size. If you want to find the element, make sure that the browser has mobile dimensions. Or if you want to catch the titles in the desktop version, in your case it is

s = driver.find_element(By.CSS_SELECTOR, "span.desktop-product-list-item__ProductName-sc-8wto4u-7.kjymBK")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading