在Selenium Python中通过XPath模式查找元素
问题描述:
我正在使用硒python和生菜来测试Django应用程序.
I am working with selenium python and lettuce to test django application.
在以下模式中有很多具有xpath的元素,我不知道文档中存在多少个这些元素.
There are many elements having xpath in the following pattern and i don't know how many of these elements exists in the document.
.//*[@id='accordion-note-1']
.//*[@id='accordion-note-2']
.//*[@id='accordion-note-3']
.//*[@id='accordion-note-4']
是否可以在 driver.find_elements_by_xpath 中使用模式?
基本上,我的目的是使所有具有这种xpath模式的项目.
Is there any way to use pattern in driver.find_elements_by_xpath ?
Basically my purpose is to get all items having this pattern of xpath.
答
不确定是否可以,但是您可以尝试使用以下xpath:
Not sure this will work, but you can try by using the below xpath:
.//*[starts-with(@id, 'accordion-note')]
这是链接 http://www.zvon.org/xxl/XSLTreference/Output/function_starts -with.html
u也可以在此处使用包含
u can also use contain here like
.//*[contains(@id, 'accordion-note')]