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

huangapple go评论67阅读模式
英文:

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

问题

Selenium Python 定位器

我在Python中使用Selenium来执行一些自动点击任务。问题是,我有一个下拉列表,它不允许我发送任何键,只能从列表中选择一个选项。

我尝试使用 browser.find_element 通过7个定位器(id,name,xpath,link test, partial link text, tag name, class name, css selector)来搜索我想要的选项,它的名称是 "Deplacement_X1(5)",但没有成功。

完整的选项元素是:

<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>

我不是一个网页开发者,有人可以给我提供一个指导或一个定位这个元素的命令吗?

英文:

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?

答案1

得分: 1

考虑以下方法:

  • Selenium的录制功能,可以捕获您的输入并将其转化为选择器。
  • 使用:nth-child(n) CSS选择器。
英文:

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

答案2

得分: 1

如果您能分享网站的URL,那将非常有助于回答这个问题。

由于下拉菜单位于<li>中,您可以使用<ul>上的click()来展开下拉菜单,并使用nth-child()来点击所需的<li>选项。

英文:

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

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

huangapple
  • 本文由 发表于 2023年5月26日 16:10:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/76338884.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定