Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在不使用标记属性的情况下查找元素?_Python_Selenium_Selenium Webdriver_Xpath_Css Selectors - Fatal编程技术网

Python 如何在不使用标记属性的情况下查找元素?

Python 如何在不使用标记属性的情况下查找元素?,python,selenium,selenium-webdriver,xpath,css-selectors,Python,Selenium,Selenium Webdriver,Xpath,Css Selectors,这两个元素有不同的标记名。如果没有标签名称,如何定位它们?或者我如何“结合”这两者?两者具有相同的类名。要删除对标记名的依赖关系,可以使用以下任一选项: 使用xpath: image = driver.find_elements_by_xpath("//img[contains(@class,'ui_qtext')]") copy = driver.find_elements_by_xpath("//p[contains(@class,'ui_qtext')]") 使用css\u选择器:

这两个元素有不同的标记名。如果没有标签名称,如何定位它们?或者我如何“结合”这两者?两者具有相同的类名。

要删除对标记名的依赖关系,可以使用以下任一选项:

  • 使用
    xpath

    image = driver.find_elements_by_xpath("//img[contains(@class,'ui_qtext')]")
    copy = driver.find_elements_by_xpath("//p[contains(@class,'ui_qtext')]")
    
  • 使用
    css\u选择器

    image_copy = driver.find_elements_by_xpath("//*[contains(@class,'ui_qtext')]")
    
image_copy = driver.find_elements_by_css_selector(".ui_qtext")