如何在不使用tag属性的情况下查找元素? [英] How to find elements without using the tag attribute?
本文介绍了如何在不使用tag属性的情况下查找元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
image = driver.find_elements_by_xpath("//img[contains(@class,'ui_qtext')]")
copy = driver.find_elements_by_xpath("//p[contains(@class,'ui_qtext')]")
我有两个具有不同tag_names的元素.我如何在没有tag_name的情况下找到它们?或我如何结合"这两个?两者具有相同的class_name.
I have this two elements with different tag_names. How do i locate them without the tag_name? Or how do i "combine" this two? Both have the same class_name.
推荐答案
To remove the dependency on the tagNames you can use either of the following Locator Strategies:
-
使用
xpath
:
image_copy = driver.find_elements_by_xpath("//*[contains(@class,'ui_qtext')]")
使用css_selector
:
image_copy = driver.find_elements_by_css_selector(".ui_qtext")
这篇关于如何在不使用tag属性的情况下查找元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文