Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding elements by xpath pattern in Selenium python

I am working with selenium python and lettuce to test django application.

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']

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.

like image 775
Adil Malik Avatar asked May 29 '26 19:05

Adil Malik


1 Answers

Not sure this will work, but you can try by using the below xpath:

.//*[starts-with(@id, 'accordion-note')]

here is the link http://www.zvon.org/xxl/XSLTreference/Output/function_starts-with.html

u can also use contain here like

.//*[contains(@id, 'accordion-note')]     
like image 142
noor Avatar answered Jun 01 '26 09:06

noor