我希望单击新建测试".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:消息:“选择"仅适用于< select>元素,而不是在<
发布评论