问题
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