1

I'm trying to click on a drop down menu, but since it is hidden, I'm getting the error:

could not be scrolled into view

I've done some digging and I see that using some JavaScript could help, but I'm not sure how to implement that into my Python script.

<div class="MuiSelect-root MuiSelect-select MuiSelect-selectMenu MuiSelect-outlined MuiInputBase-input MuiOutlinedInput-input jss987" tabindex="0" role="button" aria-haspopup="listbox" aria-labelledby="input-label-idTeam1Desktop select-idTeam1Desktop" id="select-idTeam1Desktop"><span>​</span></div>
<input name="idTeam1Desktop" type="hidden" id="idTeam1Desktop" value="">

This is what I have so far:

driver = webdriver.Firefox(profile, options=options)
driver.get("https://tradenba.com/trade-machine")
element = driver.find_element_by_xpath("//*[@id='idTeam1Desktop']")
element.click()
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Jnguyen22
  • 967
  • 2
  • 8
  • 13

1 Answers1

1

To click on the drop down menu and select the menu item with text as MIL you need to induce WebDriverWait for the element_to_be_clickable() and you can use the following based Locator Strategies:

  • Using XPATH:

    driver.get('https://tradenba.com/trade-machine')
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@id='select-idTeam1Desktop']"))).click()
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='MuiListItemText-root MuiListItemText-inset']/span/div/p[text()='MIL']"))).click()
    
  • Note: You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
  • Browser Snapshot:

tradenba

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • I'm getting this error when I try your method: "selenium.common.exceptions.StaleElementReferenceException: Message: The element reference of
    is stale; either the element is no longer attached to the DOM, it is not in the current frame context, or the document has been refreshed"
    – Jnguyen22 Nov 28 '20 at 00:30
  • When I run my script with just the first two lines of your code, I notice that the dropdown menu gets selected and appears, but quickly vanishes. – Jnguyen22 Nov 28 '20 at 00:33
  • Sorry, not sure if you were notified by my previous comments. I really appreciate your help so far! @DebanjanB – Jnguyen22 Dec 02 '20 at 04:29