Python/Selenium click on <div class="foo'>
15,743
You should use
elem = driver.find_element_by_class_name('foo').click()
or
elem = driver.find_element_by_xpath('//div[@class="foo"]').click()
Author by
J Mascis
Updated on June 28, 2022Comments
-
J Mascis almost 2 years
I try to use Selenium click() method:
elem = driver.find_element_by_class('foo').click()
on html tag:
<div class="foo"></div>
Is it possible?
-
alecxe about 8 yearsNote that
elem
would beNone
in this case. -
Andersson about 8 yearsYes, if other operations with
elem
required better to split it into two lines:elem = driver.find_element_by_class_name('foo')
andelem.click()