user3317355
user3317355

Reputation: 93

Automate Dropdown Menu in Selenium Without Select

I'm trying to select an element from a dropdown using Selenium. I'm already able to select the dropdown, but I don't know how to select the specific elements from the dropdown, since the website doesn't use select and thus I can't use the built-in select class. For reference, this is the HTML for one of the elements in the dropdown.

<div class="Di ljb1sb hIqB1e LMgvRb" jsname="wQNmvb" jsaction="" data-value="118237948356370773614" aria-selected="true" role="option" tabindex="0"> <div class="qm he" jsname="ksKsZd" style="top: 23px; left: 75px; width: 188px; height: 188px;"></div> <content class="u5 jh">BlainSupply</content> </div>

And this is the HTML for the entire dropdown

<div role="listbox" aria-expanded="false" class="Ej BtzVgc" jscontroller="YwHGTd" jsaction="click:cOuCgd(LgbsSe); keydown:I481le; keypress:Kr2w4b; mousedown:UX7yZ(LgbsSe),npT2md(preventDefault=true); mouseup:lbsD7e(LgbsSe); mouseleave:JywGue; touchstart:p6p2H(LgbsSe); touchmove:FwuNnf; touchend:yfqBxc(LgbsSe|preventMouseEvents=true|preventDefault=true); touchcancel:JMtRjd(LgbsSe); focus:AHmuwe; blur:O22p3e;b5SvAb:TvD9Pc;" jsshadow="" data-max-rows="10"><div jsname="LgbsSe" role="presentation">
  <div class="EI" jsname="d9BH4c" role="presentation">
    <div class="Di ljb1sb hIqB1e LMgvRb bf" jsname="wQNmvb" jsaction="" data-value="118237948356370773614" aria-selected="true" tabindex="0" role="option">
       <div class="qm he" jsname="ksKsZd" style="top: 27px; left: 92px; width: 197px; height: 197px;"></div>
       <content class="u5 jh">BlainSupply</content>
    </div>
    <div class="Di ljb1sb hIqB1e LMgvRb" jsname="wQNmvb" jsaction="" data-value="118324169618367399437" aria-selected="false" tabindex="-1" role="option">
        <div class="qm he" jsname="ksKsZd"></div>
        <content class="u5 jh">GPlusPages02</content>
    </div>
    <div class="Di ljb1sb hIqB1e LMgvRb" jsname="wQNmvb" jsaction="" data-value="101010111938653639529" aria-selected="false" tabindex="-1" role="option">
        <div class="qm he" jsname="ksKsZd"></div>
        <content class="u5 jh">GSitemap2</content>
    </div>
  </div>
  <div class="v5 VtTjbf eU809d" role="presentation"></div></div>

Any help would be appreciated!

Upvotes: 2

Views: 802

Answers (1)

Andrei
Andrei

Reputation: 5647

You can try this:

from selenium.webdriver.support import expected_conditions as EC

element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//content[contains(., 'BlainSupply')]")))
element.click()

as alternative you can try this xPath:

//content[contains(., 'BlainSupply')]/parent::div

because I'm not sure that content tag is clickable

Upvotes: 2

Related Questions