<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Gregary Boyles</title>
    <description>The latest articles on DEV Community by Gregary Boyles (@gregaryb).</description>
    <link>https://dev.to/gregaryb</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2172688%2F42f99b62-90fb-4dc3-9aa9-14f90d2ad144.png</url>
      <title>DEV Community: Gregary Boyles</title>
      <link>https://dev.to/gregaryb</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/gregaryb"/>
    <language>en</language>
    <item>
      <title>Python Selenium select an element via aria-label</title>
      <dc:creator>Gregary Boyles</dc:creator>
      <pubDate>Sun, 06 Oct 2024 05:23:41 +0000</pubDate>
      <link>https://dev.to/gregaryb/python-selenium-select-an-element-via-aria-label-b3k</link>
      <guid>https://dev.to/gregaryb/python-selenium-select-an-element-via-aria-label-b3k</guid>
      <description>&lt;p&gt;I have this element in a web page:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;div aria-placeholder="What's on your mind?" aria-label="What's on your mind?" class="xzsf02u x1a2a7pz x1n2onr6 x14wi4xw x9f619 x1lliihq x5yr21d xh8yej3 notranslate" contenteditable="true" role="textbox" spellcheck="true" tabindex="0" data-lexical-editor="true" style="user-select: text; white-space: pre-wrap; word-break: break-word; font-size: 24px;"&amp;gt;&amp;lt;p class="xdj266r x11i5rnm xat24cr x1mh8g0r x16tdsg8"&amp;gt;&amp;lt;br&amp;gt;&amp;lt;/p&amp;gt;&amp;lt;/div&amp;gt;&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;I am trying to select this element via this code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def DoGetTextField(browserChrome):
    TextField = None
    arrayAriaLabels = ["Whats on your mind?", "Write something"]
    nWaitSeconds = 5
    for nI in range(0, len(arrayAriaLabels)):
        Wait = WebDriverWait(browserChrome, nWaitSeconds)
        strSelectorString = "[aria-label='" + arrayAriaLabels[nI] + "']"
        TextField = Wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, strSelectorString)))
        Wait = WebDriverWait(browserChrome, nWaitSeconds)
        TextField = Wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, strSelectorString)))
        if TextField is not None:
            break

    return TextField

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But that damn single quote in the aria-label is screwing me up.&lt;br&gt;
aria-label="What's on your mind?"&lt;/p&gt;

&lt;p&gt;If I leave that single quote out then I get a timeout exception - expected.&lt;/p&gt;

&lt;p&gt;But if I include the single quote as ', '' or \' then I get an invalid or illegal selector exception.&lt;/p&gt;

&lt;p&gt;How do I resolve it?&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
