Search code examples
pythonseleniumwebautomation

Python Selenium - get element with a date-rolename


I have the following HTML markup:

<div data-request-type="person" class="_entry _line _e _selected" id="c1055e27-0cfe-4f93-8bea-28a3421d842e" data-rolename="Member" data-isoptional="true">
    <div class="_subindicator _gray">&nbsp</div>
    <div class="_removePers">&nbsp;</div>
    <div class="_voluntaryPers">&nbsp;</div>
    <div class="_text">Member</div>
</div>

I have to click on the first <div> using .click().

But now I don't know how to find this with selenium. I already tried it with XPATH, but I have several elements with different IDs on this page. And the IDs are always regenerated. This does not work.

Does anyone have an idea?

I tried it with a lot of solutions...but nothing works.

My last one - to take a inner div with class _text

   getAllMembers = browser.find_element_by_css_selector('td._text').get_attribute('innerHTML')

Please help - how can I do this with Selenium? :-)


Solution

  • Try below xpath :

    wait = WebDriverWait(driver, 20)
    
    wait.until(EC.element_to_be_clickable((By.XPATH, "//div[@class='_entry _line _e _selected'][@data-rolename='Member']"))).click()
    

    Note : please add below imports to your solution

    from selenium.webdriver.support import expected_conditions as EC
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support.ui import WebDriverWait