Skip to content
Advertisement

Click through dropdown menu with selenium

I am trying to create flashcards on quizlet.com with selenium. If you visit, you will see a “Create” button (or just a “+” depending on window size) in the navbar, when you click this it turns into a dropdown menu with 3 more buttons: ‘Study Set’, ‘Folder’ and ‘Class’. (I am trying to click Study Set)

First, I am not even sure If I need to have selenium click the first ‘Create’ button to access the ‘Study Set’ button or if I can just jump straight to the ‘Study Set’ button. Anyway, here is the html related to the ‘Create’ button and ‘Study Set’ button, respectively:

JavaScript

and: (Note, all 3 buttons share the class ‘UILink’, the first button is the ‘Study Set’ button and the comments are mine)

JavaScript

Python code:

JavaScript

When I run this, it throws

JavaScript

Though study_set_button should definitely be referencing a button element, I believe? Thanks for any help with this.

EDIT: Upon searching, I found is_displayed() and ran

JavaScript

this returns True and False, respectively. Think my problem lies somewhere there.

Advertisement

Answer

This is what I found to work. It was not easy to find a unique locator for “Study set” inside the dropdown. There are two “Study set” elements on the page and the first one in the DOM is not visible. I added the waits just to be safe since you are clicking and the dropdown has to load. You may not need the waits but it won’t hurt to have them (it won’t slow anything down) just in case.

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement