title: dynamic css selector - Selenium python
body: <p>I am trying to click on button on a webpage that will take me to a user's email settings. I want to find a css selector based on the username or email address that is on the webpage then click on that username to get into the settings.</p>
  <p>The problem is that the css selector has no way to determine the user I want except for the flag called <code>data-testuserid=</code> that holds the email address.</p>
  <p>Here is what the full element looks like for the test email I am trying to access:</p>
  <pre><code>&lt;a id=&quot;ctl00_ContentPlaceHolder1_ctlCurrentTab_ctlUserList_ctlUserList_rptList_ctl19_ctlRowContent__lnkUser2&quot; class=&quot;linkMild&quot; data-testuserid=&quot;testmuser@AlloySystems.com&quot; href=&quot;javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&amp;quot;ctl00$ContentPlaceHolder1$ctlCurrentTab$ctlUserList$ctlUserList$rptList$ctl19$ctlRowContent$_lnkUser2&amp;quot;, &amp;quot;&amp;quot;, true, &amp;quot;&amp;quot;, &amp;quot;&amp;quot;, false, true))&quot;&gt;test user&lt;/a&gt;
  </code></pre>
  <p>Here is the css selector that comes out if you copy it from chrome by right clicking on the element and choosing <strong>copy selector</strong>:</p>
  <pre><code>#ctl00_ContentPlaceHolder1_ctlCurrentTab_ctlUserList_ctlUserList_rptList_ctl19_ctlRowContent__lnkUser2
  </code></pre>
  <p>noticed the <code>ct119</code>? That is the exact place on the website where that email button exists, but what if I want to search for someone else? How can I got about creating a css selector that would include the email or alias?</p>
  <p>Here is a picture of the issue:
  <a href="https://i.stack.imgur.com/GJyfG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GJyfG.png" alt="enter image description here" /></a></p>
  <p><strong>I do have a work around for now but its not good</strong> - For now, I use the search bar to search for the email I want so it shows up in the list. The problem is the website is trash and sometimes the webpage will tend to freeze and get stuck for now reason. I refresh fixes the issue but I wanted to get around that issue by exact clicking on the css selector of the email address I want.</p>
  <p>I hope that makes sense. Thank you everyone.</p>
  <p><strong>Update</strong></p>
  <p>I tried the suggestion that @Strik3r propsed but it didn't work for me. (I unless I typed it wrong.)</p>
  <p>Here is the code so far:</p>
  <pre><code>def reset_email():
      time.sleep(1)
      wait = WebDriverWait(browser_options.browser, 15)
      wait.until(EC.element_to_be_clickable((By.XPATH, (&quot;//a[@data-testuserid=&quot;+email_selection_only.email_select+&quot;]&quot;))))
      im_defaultpolicy = browser_options.browser.find_element_by_xpath(&quot;//a[@data-testuserid=&quot;+email_selection_only.email_select+&quot;]&quot;) #ctl00_ContentPlaceHolder1_ctlCurrentTab_ctlUserList_ctlSearchOptions_txtSearch
      im_defaultpolicy.send_keys(Keys.ENTER)
  </code></pre>
  <p>Here is the result:</p>
  <pre><code>line 147, in reset_email
      wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, (&quot;//a[@data-testuserid=&quot;+email_selection_only.email_select+&quot;]&quot;))))
    File &quot;/home/tech/.local/lib/python3.8/site-packages/selenium/webdriver/support/wait.py&quot;, line 80, in until
      raise TimeoutException(message, screen, stacktrace)
  selenium.common.exceptions.TimeoutException: Message: 
  </code></pre>