R
R
rsefsE2020-09-02 15:51:25
selenium
rsefsE, 2020-09-02 15:51:25

How to click on an element in Selenium?

EbNCR.jpg

I want to click on the blog avatar, I try to hook on the "avatar circle" class, but I'm flying into exption. Here is the code:
option = webdriver.ChromeOptions()
driver = webdriver.Chrome(chrome_options=option)

url = 'https://www.tumblr.com/search/tatto+'

driver.get(url)

albums =  driver.find_element_by_class_name('avatar circle')
# albums.click()
a = albums.size
x = random.randint(-a['height'],a['height'] )
y = random.randint(-a['width'], a['width'])
# action = ActionChains(driver)
ActionChains(driver).move_to_element_with_offset(albums, x, y).click().perform()


Crashes on line
albums =  driver.find_element_by_class_name('avatar circle')
. Why? How to do it differently?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2020-09-02
@soremix

The function looks for an element with one class, you pass two.

albums =  driver.find_element_by_xpath('//div[@class="avatar circle"]')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question