Locating a Web Element in a Drop-down list by Selenium Python

73 views Asked by At

Selenium Python Locator

I use Selenium in Python to to some auto-clicking task for me. The thing is I got this drop-down list, which do not let me send any keys, only select 1 of the option from the list.

I tried to use browser.find_element to search for it by the option I want which named "Deplacement_X1(5)" by 7 locators(id,name,xpath,link test, partial link text, tag name, class name, css selector) but it didn't work.

Full of the option's element is :

<li class="MuiButtonBase-root MuiMenuItem-root MuiMenuItem-gutters MuiMenuItem-root MuiMenuItem-gutters css-18wioi6" tabindex="0" role="option" aria-selected="false" data-value="175155">Deplacement_X1(5)
<span class="MuiTouchRipple-root css-w0pj6f"></span>
</li>

I'm not a web dev, can anyone give me an instruction or a command to locate this?

2

There are 2 answers

0
אוהד סירקיס On

Consider the following approaches:

  • Selenium's recording feature which would capture your input and turn it to selectors
  • Using the :nth-child(n) css selector
0
Munish Gupta On

If you could share the site URL that would be really helpful to answer the question.

Since the drop down is in <li> you could use the click() on <ul> to expand the drop down and use nth-child() to click the desired option from <li>.