找到使用硒(Python)的破折号下拉元素

发布于 2025-02-11 09:35:09 字数 467 浏览 1 评论 0原文

我意识到破折号布局元素与传统的UI布局不同。我正在尝试自动化测试通常为“选择”类型的下拉元素。因此,硒语法和选择值是:

select = select(driver.find_element(By.XPATH, "...")
select.select_by_visible_text("NCS")

我得到错误:selenium.common.exceptions.unbectednectectemetagexception:消息:仅选择元素上的作品,而不是在

下拉列表的布局上使用如下: 感谢您的帮助!

I realized that dash layout elements are different from the traditional UI layout. I am trying to automate testing a dropdown element which would normally be of type "select". So the selenium syntax and select th value would be:

select = select(driver.find_element(By.XPATH, "...")
select.select_by_visible_text("NCS")

I get the error: selenium.common.exceptions.UnexpectedNameTagException: Message: select only works on elements, not on

The layout for the dropdown is as follows:
enter image description here
Thanks for your help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

有深☉意 2025-02-18 09:35:09

由于未选择标签,因此您不能使用Select类选择下拉菜单。您必须找到选择的下拉菜单,然后单击将显示下拉列表的内容。然后,您可以通过提供XPath来单击所需的下拉项。

driver.find_element(By.XPATH, "...").Click();
driver.find_element(By.XPATH, "//div[text()='Role']").Click();

As tag is not Select, you cant use Select class for selecting dropdown. You have to find the Select dropdown and click on that which will show dropdown list. Then you can click on desired dropdown item by providing xpath.

driver.find_element(By.XPATH, "...").Click();
driver.find_element(By.XPATH, "//div[text()='Role']").Click();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文