有没有办法在 Python Selenium 中通过属性查找元素? [英] Is there a way to find an element by attributes in Python Selenium?

查看:49
本文介绍了有没有办法在 Python Selenium 中通过属性查找元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个这样的 html 片段:

I got a html snippet like this:

<input type="text" node-type="searchInput" autocomplete="off" value="" class="W_input" name="14235541231062">

这个元素在html中唯一的唯一标识是属性node-type="searchInput",所以我想用Python的some method来定位它硒有点像这样:

The only unique identity of this element in the html is the attribute node-type="searchInput",so I want to locate it by using some method of Python selenium sort of like this:

search_elem = driver.find_element_by_xxx("node-type","searchInput") # maybe?

我已经检查了 selenium(python) 用于定位 elems 的文档 但没有得到如何通过 node-type 属性定位这个元素的线索.有没有明确的方法可以在 python selenium 中找到这个 elem?

I have checked the selenium(python) document for locating elems but didn't get a clue of how to locate this elem by the node-type attr. Is there a explicit way to locate this elem in python selenium?

推荐答案

您可以通过 xpath 获取它并检查 node-type 属性值:

You can get it by xpath and check the node-type attribute value:

driver.find_element_by_xpath('//input[@node-type="searchInput"]')

这篇关于有没有办法在 Python Selenium 中通过属性查找元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆