Skip to content
Advertisement

How to extract the values of the alt atributte within img with selenium python

I have the following problem, I haven’t been able to solve it. I have to extract the text that appears in an alt attribute of an image. The id always changes, as does the contained alt.

Example

I noticed that the id only changes in this part

JavaScript

Anyway, I am still unable to log in.

Advertisement

Answer

To extract and print the values of the alt attribute you have to induce WebDriverWait for visibility_of_all_elements_located() and you can use either of the following locator strategies:

  • Using CSS_SELECTOR:

    JavaScript
  • Using XPATH:

    JavaScript
  • Note: You have to add the following imports :

    JavaScript
Advertisement