Reputation: 21
so I have this kind of xpaths:
html/body/div[3]/div[3]/div/div/div[2]/div/div[2]/div[1]/div[1]
then
html/body/div[3]/div[3]/div/div/div[2]/div/div[2]/div[2]/div[1]
then
html/body/div[3]/div[3]/div/div/div[2]/div/div[2]/div[3]/div[1]
etc..
as you can see, the only number that is being increased is the second on the right div[1], div[2], div[3]
And I need to make actions with 100's of this kind of xpaths. Are there any possibility, for example, to save it to variable and just add 1 to the actual number, and for example run it in for loop?
so my program would pick all of those 3 xpaths automatically.
Thanks for all replies! :)
Upvotes: 1
Views: 468
Reputation: 33343
Seems like a straightforward use of a for loop using range()
:
for i in range(1, 101):
xpath = f'html/body/div[3]/div[3]/div/div/div[2]/div/div[2]/div[{i}]/div[1]'
# now do something with xpath
Upvotes: 1