Looping multiple buttons in dynamic webpage


#1

Hi all,
Can anybody help me for this?
How to loop buttons in webpage where we are not sure how many buttons will come like if i saw today it is 5 button but may be tomorrow it will be 10 buttons…How to loop through all the buttons dynamically?
Thanks
sharad kumar


How to Iterate nested div element using selenium script
#2

#3

Hi ,
My requirement is related to Dynamic Web page…There i want to loop through buttons like today i have 5 buttons may be based on execution tomorrow it may have more or less button…How to handle this dynamic nature of execution
Thanks
Sharad Kumar


#4

@sharad_kumar,

Here is an example to click through each button on the bootstrap Buttons

recording archive: dynamic-web-page.7z (1.4 KB)

The idea is to:

  • get a list of all buttons using 1 XPATH - https://getbootstrap.com/docs/4.0/components/buttons/
  • for each list element:
    – click on a button by dynamic XPATH - //div[@class='bd-example'][1]/button[${iterator}]
    – increase the ${iterator} variable by 1

As a result, robot will click through all buttons one by one using the following XPATHs:

//div[@class='bd-example'][1]/button[1]
//div[@class='bd-example'][1]/button[2]
//div[@class='bd-example'][1]/button[3]
//div[@class='bd-example'][1]/button[4]
//div[@class='bd-example'][1]/button[5]
//div[@class='bd-example'][1]/button[6]
//div[@class='bd-example'][1]/button[7]
//div[@class='bd-example'][1]/button[8]
//div[@class='bd-example'][1]/button[9]