-
Notifications
You must be signed in to change notification settings - Fork 1.4k
If an xpath corresponds to multiple elements on a page, how do you know the number of those elements #1401
-
I want to know the number of elements and click on them
Beta Was this translation helpful? Give feedback.
All reactions
Example with button
:
Find the number of button
elements on a page:
len(self.find_visible_elements("//button"))
To click all the buttons:
self.click_visible_elements("//button")
Replies: 3 comments 2 replies
-
Example with button
:
Find the number of button
elements on a page:
len(self.find_visible_elements("//button"))
To click all the buttons:
self.click_visible_elements("//button")
Beta Was this translation helpful? Give feedback.
All reactions
-
Thanks
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
-
I need to click the buttons in order, The way I do it now is I get the length and I concatenate the elements in order, Is there a more elegant way to do it
@mdmintz
The way I use it now:
for i in range(1, len(self.find_visible_elements("//button"))):
self.click(f'("//button")[{i}]', timeout=10, delay=1)
self.sleep(10)
Because I do something after every click, this method is not for me
self.click_visible_elements("//button")
Beta Was this translation helpful? Give feedback.
All reactions
-
If you have to perform an action between the clicks, then your way should work. I recommend changing the sleep()
to waiting for an actual element, as that would save time from unnecessary sleeping/waiting.
Beta Was this translation helpful? Give feedback.
All reactions
-
ok,Thank you for reply
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1