Home>
We want to perform page processing based on the existence of class.
If class "bonus" exists and I want to confirm by printing "Yes":
# Class "bonus" actually exists but not printed
if driver.find_element_by_class_name ("bonus") == True:
print ("Yes")
# Error below
if len (driver.find_element_by_class_name ("bonus"))>0:
print ("Yes")
TypeError: object of type 'WebElement' has no len ()
# Using try will print correctly
try:
driver.find_element_by_class_name ("bonus")
print ("Yes")
except:
print ("No")
Yes
I would like to process with an if statement without using a try. Is this possible?
I'm sure it's a naive question, but I'd be happy if you could tell me.
Thanks for your cooperation.
-
Answer # 1
Related articles
- python - link extraction method in the specified class
- [python] when importing pandas on vs code, the error "the specified module cannot be found" is displayed
- python: i want to check the match of the elements of the data frame
- python - i want to search for a specific value in a row specified by a two-dimensional array
- python - read_excel specified range column cannot be read
- python - 3 class classification by keras
- python 3x - how to use python class
- javascript - if the specified data exists in ajax communication, i want to send it all at once
- i want to extract one character string of text that exists in multiple files with python
- file not found error even though python file exists
- python 3x - i want to change the background color of the specified line in python3 tkinter treeview
- python - cannot inherit a class with multiple arguments
- python - yolo i want to detect only a specific class
- how to add python built-in class method
- python - i want to change the csv file name every time i loop with the for in syntax and save it in the specified folder
- python - if the column that is pandas is other than the specified string, i want to rewrite the string in another column
- python - i want to check the existence of files on an external server
- python about iterative processing with specified numbers
- [python] functions in the class that inherits formatter do not work
- [python] how to check the version @mac
Related questions
- python 3x - about the contents of python error code
- [python] [selenium] css pseudo-element state acquisition
- python 3x - bring the chrome window opened in selenium to the front
- python 3x - i can't get the text of the span tag using selenium
- python - i made a code to search a website tag as a string, but can it be simplified?
- python - i want to search only a part of html (a certain selector) with find_all of beautifulsoup
- python - i'm using selenium the text sent by send_keys to the input tag disappears when the text is sent by send_key to the next
- python - the library installed by pip cannot be imported no module named'selenium'
- internet explorer - i am testing using selenium (ie11), but i cannot clear the cookie i entered last time
- python - find_element_by_id method error
How about using the following method?
Since the return value is a list, is it possible to determine the presence or absence of the target tag by obtaining its length?