2

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!

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

3 Comments

This works in getting the correct element, but for some reason it doesn't let me click it. The console gives me an selenium.common.exceptions.ElementNotVisibleException: Message: element not visible error. Do you know why this might be?
try in devtools of browser to check my xpath, if it locates one element and the right one
check also if your page has iframe, if yes check if element is inside iframe

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.