pythonseleniumbeautifulsoupwebdriverwaitmechanicalsoup

Click on button which changes its id everytime


I work with Python and Selenium. The mission is to click on button with text '+like' or on column 'td' with class='profile-image'. But button hasn't id and it's class 'more-likes' is used in others buttons. Same situation with div with class 'profile-image-button' (div's class id used in others 'divs'). I tried to take id of 'td' :

button = photos.find('td', class_='profile-image')
print(button.get_id)

Output is 'None'

Here is html code of webpage:

<div id="category7515692" class="category-content" data-content="present" data-collapsing="true">
  <table class="pictures" data-columns-count="12" data-type="gallery">
    <tbody class="" data-selec="7565904" data-name="beauty" data-live="true">
      <tr data-mutable-id="MR1main" class="header">
        <td class="main-row-buttons" rowspan="1" data-mutable-id="Bmain">
          <table>
            <tbody>
              <tr>
                <td class="profile-image" id="view-75634" data-event-more-view="event-more-view" data-selec="7565904" islive="true" isseparatedbutton="false">
                  <div class="profile-image-button">
                    <span class="more-likes">+like</span>
                  </div>
                </td>
              </tr>
            </tbody>
          </table>
        </td>
      </tr>
    </tbody>
  </table>
</div>

How can I click on button or how can I take id?


Solution

  • The desired element is an React element so to click the element you have to induce WebDriverWait for the element to be clickable and you can use either of the following solutions: