Find elements with specific class name

Mehran Goudarzi

for chrome, I install ChroPath to find elements on the page.

I want to find XPath for like elements on Instagram Page, but seems that not work :

//span[contains(@class,'glyphsSpriteHeart__outline__24__grey_9 u-__7')] 

also, I try it :

/html[1]/body[1]/div[3]/div[1]/div[2]/div[1]/article[1]/div[2]/section[1]/span[1]/button[1]/span[1]

when selenium click :

elenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"div._2dDPU.vCf6V div.zZYga div.PdwC2._6oveC article.M9sTE.L_LMM.JyscU div.eo2As section.ltpMr.Slqrh span.fr66n button.coreSpriteHeartOpen.oF4XW.dCJp8 > span.glyphsSpriteHeart__outline__24__grey_9.u-__7"}

how can I find XPath? any good extension or something?

Robbie Wareham

how can I find XPath? any good extension or something?

You cannot "find" the Xpath of an element. There are many, many XPath's that will find any element. Some will be stable, others will be unstable. The decision on which Xpath to use is based upon your understanding and experience of Selenium, and you understanding of how the Application Under Test is written and behaves.

If you are looking for a tool to experiment with different XPaths, then Chrome's built-in Developer Tools Console allows you to test both Xpath & CSS Selectors; enter image description here

In your specific scenario about finding elements by class name, then CSS Selector is a much better choice than XPath as CSS selectors will treat multiple classes as an array where as XPath sees "class" as a literal string, hence why you needed to use "contains".

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Selenium Not Locating ALL elements with specific class name

Click on specific button based on name of the class or elements

Trying to find all <a> elements without a *specific* class

selenium hangs at find elements by class name with python

How to find from elements with one to multiple class names just the ones which feature exactly a specific and sole class name (and not any other)?

Find specific child element and change class name

Find All HREF with specific class name with domdocument

How to find specific dynamic class name checkbox?

How to find controls inside a class with specific class name

Count specific elements and add count to class name using jquery

JavaScript get all elements by class name, while excluding specific classes?

Trying to scrape data out of <div> elements with specific class name

How to use BeautifulSoup to find specific class elements on a web page

Issue running driver.find_elements_by_class_name

Webdriver: How to find elements when class name contains space?

len(browser.find_elements_by_class_name('foo')) gives 0

How to find elements that do not include a certain class name with selenium and python

Selenium Python | 'find_elements_by_class_name' returns nothing

Find number of elements under a particular class name jquery?

Python+Selenium How to find elements by class name length

Python Selenium find elements by class name doesn't work

How to correctly find elements by class name on Python? Selenium related

How can I find elements with variative class name in Python?

Selenium Can't find elements by CLASS_NAME

jquery find all hidden input fields with specific class name

Find element in Array with specific class name and get its ID

Removing elements by class name?

jQuery function to loop through elements and set class names based on order compared to an element with a specific class name

How to find elements by class