How to find elements without using the tag attribute?

倾然丶 夕夏残阳落幕 提交于 2020-06-16 17:25:42

问题


image = driver.find_elements_by_xpath("//img[contains(@class,'ui_qtext')]")
copy = driver.find_elements_by_xpath("//p[contains(@class,'ui_qtext')]")

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.


回答1:


To remove the dependency on the tagNames you can use either of the following Locator Strategies:

  • Using xpath:

    image_copy = driver.find_elements_by_xpath("//*[contains(@class,'ui_qtext')]")
    
  • Using css_selector:

    image_copy = driver.find_elements_by_css_selector(".ui_qtext")
    


来源:https://stackoverflow.com/questions/62109805/how-to-find-elements-without-using-the-tag-attribute

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!