UnexpectedTagNameException:消息:“选择"仅适用于< select>元素,而不是在< li>上使用Selen

编程入门 行业动态 更新时间:2024-10-26 19:40:38
本文介绍了UnexpectedTagNameException:消息:“选择"仅适用于< select>元素,而不是在< li>上使用Selenium从Dropdown中选择li元素时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我希望单击新建测试".HTML代码看起来像这样.我是新来的,开始学习使用selenium-python的自动化.

I wish to click on New Test. The HTML code looks something like this. I'm new here and beginning to learn automation using selenium-python.

<li id="testing"> <ul class="dd"> <li><a href="javascript:toolsPopup('/abc/xyz/text.html');"><span>New Test</span></a></li> <li><a href="javascript:toolsPopup('/abc/xyz/list.html');"><span>Test List</span></a></li> </ul> </li>

我要使用的代码

element=driver.find_element_by_id('testing') drp=Select(element) drp.select_by_visible_text('New Test')

但是出现错误

seleniummon.exceptions.UnexpectedTagNameException: Message: Select only works on <select> elements, not on <li>

任何帮助将不胜感激.谢谢!

Any help would be highly appreciated. Thanks!

推荐答案

Select方法仅适用于具有HTML标签选择的下拉菜单.在您的情况下,您不能使用select方法,只需为要从下拉菜单中检测到的元素编写定位符(XPath,CSS或其他).

The Select method works only for dropdowns which has HTML tag select. In your case you can not use a select method, just write locator( XPath, CSS, or else) for the element which you want to detect from the dropdown.

在您的情况下,所需元素的XPath应该是:

In your case the XPath of the element which you wanted should be:

//li[text()='New Test']

更多推荐

UnexpectedTagNameException:消息:“选择"仅适用于&lt; select&gt;元素,而不是在&lt

本文发布于:2023-10-31 01:54:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1544644.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:元素   是在   适用于   而不   消息

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!