1
votes

I am using selenium with python to try and click through a dropdown menu. However the options the dropdown menu produces are not visible in the source code of the webpage.

I have not been able to find a way that lets me select an item in the dropdown by name.

So far I am able to login and click on the menu to produce the dropdown as such:

courses = driver.find_element_by_link_text("Select a course...").click()

However after this, I am not sure how to access and click the elements produced by the above click.

Here is a snippet of the HTML that activates the dropdown.

<a class="d2l-menuflyout-opener d2l-clickable" onclick="return false;" aria-haspopup="true">
<span class="d2l-menuflyout-text d2l-menuflyout-emphasis">Select a course...</span><span class="d2l-menuflyout-arrow d2l-menuflyout-arrow-open d2l_1_41_179"></span><span class="d2l-menuflyout-arrow d2l_1_40_548 d2l-menuflyout-arrow-closed"></span>

Here is a screenshot of what the menu looks like after the .click() call.

screenshot

Once the menu opens, I am not sure how to select the one I want since I don't know how the values or id's of the options are stored as it is not in the source code.

1
you have to use explicit wait to wait for the elements which are produced by click and post the using any locator you can access them - thebadguy
thank you! so I see what you mean with something like this element = WebDriverWait(driver, 10).until( EC.presence_of_element_located((By.ID, "myDynamicElement")) but my problem is I don't know how to find the link I want to click since it is not visible in the HTML.. - Carlos G. Oliver
can you try visibility_of_element_located instead of presence_of_element_located with xpath in my answer . - NarendraR

1 Answers

0
votes

What you have shared in your html, Select a course... is not a link text it is under span tag you need to try alternative like

driver.find_element_by_xpath(".//a/span[contains(text(),'Select a course')]").click()