Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

trying to click a html button with selenium with python

Trying to go trough a website using selenium to parse some stuff,
but i cant click it on a button to load a pop up java script page

using firefox + geckowebdriver (latest)


view_larger_image_button = driver.find_element_by_xpath('//span[text()="View larger image"]')
driver.click(view_larger_image_button)

Here is the button :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel


<div class="main-link" data-spm-anchor-id="a2700.details.0.i4.2b7b5fc5f54UAP"><i class="detail-next-icon detail-next-icon-search detail-next-small"></i><span>View larger image</span></div>

i get the following error:

  File "image.py", line 17, in <module>
    view_larger_image_button = driver.find_element_by_xpath('//span[text()="View larger image"]')
AttributeError: 'WebDriver' object has no attribute 'find_element_by_xpath'

>Solution :

All the find_element_by_* and find_elements_by_* methods are deprecated in current Selenium versions. You need to use driver.find_element(By.CLASS_NAME, " "), driver.find_element(By.XPATH, " ") etc. methods.
So, instead of driver.find_element_by_xpath('//span[text()="View larger image"]')
you should use

driver.find_element(By.XPATH, '//span[text()="View larger image"]')

You will also need this import:

from selenium.webdriver.common.by import By
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading