I want to get custom data attributes of html as elements using Python Selenium

In HTML documents, id is unique in the document but class is not, so if there are multiple identical class names in the document, you may need to turn the result of find_elements_by_class_name () (element with s) .. For example, if including an attribute makes it unique, you can use get_attribute () to get the attribute, and if you think it, do what you want to do (such as clicking) (below). See code). If not, I think you have to think about how to make it unique in the document. I think that the xpath and css selectors that can be obtained with the development tool of the browser are unique because they are unique.


elems = driver.find_elements_by_class_name("name of the class(*1)") # *1:適切なname of the classを指定してください。
for elem in elems:
    attr = elem.get_attribute("Attribute name(*2)") # *2:適切なAttribute nameを指定してください。
    if (attr == "Attribute value that you think matches"):
        elem.click()

Recommended Posts

I want to get custom data attributes of html as elements using Python Selenium
I want to get League of Legends data ③
I want to get League of Legends data ②
I want to get League of Legends data ①
I tried to get data from AS / 400 quickly using pypyodbc
[Python] I tried to get various information using YouTube Data API!
I tried to get data from AS / 400 quickly using pypyodbc Preparation 1
(Python Selenium) I want to check the settings of the download destination of WebDriver
I want to email from Gmail using Python.
I tried to get CloudWatch data with Python
How to get dictionary type elements of Python 2.7
Python programming: I tried to get (crawling) news articles using Selenium and BeautifulSoup4.
I want to get / execute variables / functions / classes of external files from Python
I tried to get the information of the .aspx site that is paging using Selenium IDE as non-programming as possible.
[Python] I tried to get Json of squid ring 2
I want to use a python data source in Re: Dash to get query results
Start to Selenium using python
I want to specify another version of Python with pyvenv
I want to be able to analyze data with Python (Part 1)
[Python] I want to get a common set between numpy
I want to start a lot of processes from python
I want to get the operation information of yahoo route
I want to be able to analyze data with Python (Part 4)
I want to be able to analyze data with Python (Part 2)
I want to automatically attend online classes with Python + Selenium!
I want to judge the authenticity of the elements of numpy array
I want to know the features of Python and pip
[Python] I tried collecting data using the API of wikipedia
Keras I want to get the output of any layer !!
I know? Data analysis using Python or things you want to use when you want with numpy
[Question] How to get data of textarea data in real time using Python web framework bottle
I want to get the name of the function / method being executed
I tried to get a database of horse racing using Pandas
I tried to get the index of the list using the enumerate function
I tried to make a regular expression of "amount" using Python
I want to extract an arbitrary URL from the character string of the html source with python
I want to read the html version of "OpenCV-Python Tutorials" OpenCV 3.1 version
I tried to make a regular expression of "time" using Python
I want to output the beginning of the next month with Python
I tried to make a regular expression of "date" using Python
I want to use both key and value of Python iterator
I tried to get a list of AMI Names using Boto3
Get and set the value of the dropdown menu using Python and Selenium
Python techniques for those who want to get rid of beginners
I want to debug with Python
I tried to get and analyze the statistical data of the new corona with Python: Data of Johns Hopkins University
I tried to get the batting results of Hachinai using image processing
[Note] I want to completely preprocess the data of the Titanic issue-Age version-
[Python memo] I want to get a 2-digit hexadecimal number from a decimal number
Python Note: When you want to know the attributes of an object
Click the Selenium links in order to get the elements of individual pages
I want to batch convert the result of "string" .split () in Python
I want to explain the abstract class (ABCmeta) of Python in detail.
I tried to get the authentication code of Qiita API with Python.
Try to get the road surface condition using big data of road surface management
I want to color a part of an Excel string in Python
I tried to get the movie information of TMDb API with Python
I tried to perform a cluster analysis of customers using purchasing data
Python: I want to measure the processing time of a function neatly
I want to make a web application using React and Python flask
Get html from element with Python selenium