Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/78.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 Selenium:无法通过链接文本找到元素_Python_Html_Selenium_Selenium Webdriver - Fatal编程技术网

Python Selenium:无法通过链接文本找到元素

Python Selenium:无法通过链接文本找到元素,python,html,selenium,selenium-webdriver,Python,Html,Selenium,Selenium Webdriver,我正在尝试从其他选项列表中选择seltarget HTML: 这在目前是有效的,因为seltarget恰好是列表中的第五位。上面的行将选择列表中第五个选项。我想更具体一点,选择元素seltarget按链接定位文本仅适用于标记。若要定位此元素,可以使用该类(如果它是唯一的) driver.find_element_by_class_name('filter-item').click() 或数据ID属性 driver.find_element_by_css_selector('[data-reac

我正在尝试从其他选项列表中选择seltarget

HTML:

这在目前是有效的,因为seltarget恰好是列表中的第五位。上面的行将选择列表中第五个选项。我想更具体一点,选择元素seltarget

按链接定位文本仅适用于标记。若要定位此元素,可以使用该类(如果它是唯一的)

driver.find_element_by_class_name('filter-item').click()
或数据ID属性

driver.find_element_by_css_selector('[data-reactid*="3.1.0.0.1.0.0.3.0.0.0.3"]').click()
要按文本定位,还可以使用css_选择器

或xpath

按链接文本定位仅适用于标记。若要定位此元素,可以使用该类(如果它是唯一的)

driver.find_element_by_class_name('filter-item').click()
或数据ID属性

driver.find_element_by_css_selector('[data-reactid*="3.1.0.0.1.0.0.3.0.0.0.3"]').click()
要按文本定位,还可以使用css_选择器

或xpath

如果希望通过文本查找div,可以使用以下命令

driver.find_element_by_xpath("//div[text()='seltarget']")
如果希望通过文本查找div,可以使用以下命令

driver.find_element_by_xpath("//div[text()='seltarget']")

请参见您可以通过reactid选择或向seltarget添加范围请参见您可以通过reactid选择或向seltarget添加范围我可以通过其数据reactid来选择seltarget。我仍然希望能够通过它的名称选择它:seltarget列表中的所有选项都有class=filter item任何其他建议?@Chris我通过文本添加了选项我能够通过它的数据ID来选择seltarget。我仍然希望能够通过名称选择它:seltarget列表中的所有选项都有class=filter项还有其他建议吗?@Chris我在文本中添加了选项
driver.find_element_by_xpath("//div[text()='seltarget']")