How to click unopened tabs where numbers change

How do I click all pages of closed tabs where the value changes when tabs are clicked? (see image below)

Take a script based on this question with the following approach:

clickMe = wait(driver, 10).until( EC.element_to_be_clickable((By.XPATH, path + '[%s]' % str(index - 1)))) 

Works great for most pages, but I don’t see how this can be used in this case. Any idea how you can get around this problem?

The reason it doesn't work is because as soon as you click on an unopened tab, the values ​​of the numbers change. This means that the task is trying to click on elements that previously existed, but the values ​​of the numbers changed when the closed tab was opened. This is better shown in the image below.

Say you have //div[@class="KambiBC-collapsible-container KambiBC-mod-event-group-container"][1] In the figure below you can see that the above selector will change depending on when the project itself clicks the tabs and when the web page loads. A webpage has the habit of randomizing open and closed tabs. So this explains why it clicks on some elements and then breaks completely, or if you add try except, click only some elements and finish.

exit:

 1 2 3 4 #Stops working 

Desired

 1 2 3 4 etc,, (Clicks all the pages) 

enter image description here The above images:

 //div[@class="KambiBC-collapsible-container KambiBC-mod-event-group-container"][1]` 

You can see how this will cause problems later. The image on the right cannot find // div [@ class = "KambiBC-collapsible-container KambiBC-mod-event-group-container"] [11], where the one on the left can be based on the order of clicks.

outerhtml

-one
python selenium
source share
1 answer

Instead of using the index to refer to these “tabs”, you need an alternative way to uniquely identify each of them.

One solution is to work with the site’s developers to add the id or name attribute to the “KambiBC folding container” for each tab.

Another solution, if you use the "Object Model Model" approach, would be to create a method on the page that provides a list of available tabs that can then be referenced in the header text. Then you just keep track of which ones you have opened.

Another decision will depend on the functionality of the site. Perhaps you can use the fact that if the tab was open, it looks like there is a "KambiBC-extended" class in the container. If the tab remains open until you explicitly close it, you can simply get a list of all containers that do not have the KambiBC-extended class, and select one to expand it, repeating it until it expands.

0
source share

All Articles