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()
Share:
15,743
J Mascis
Author by

J Mascis

Updated on June 28, 2022

Comments

  • J Mascis
    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
    alecxe about 8 years
    Note that elem would be None in this case.
  • Andersson
    Andersson about 8 years
    Yes, if other operations with elem required better to split it into two lines: elem = driver.find_element_by_class_name('foo') and elem.click()