How to click unopened tabs where the numbers change

2024/10/6 9:57:32

How do I click all the unopened tabs pages where the value changes when you click tabs? (see image below)

Take the following script, based off of 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 the large majority of pages, however I cannot see how it can be used in this case. Any idea how you can get around this issue?

The reason it does not work is because as soon as you click an unopened tab, the number values change. This means the job is trying to click elements that used to exist, but the number values changed when you opened a closed tab. This is better illustrated in the image below.

Say you had //div[@class="KambiBC-collapsible-container KambiBC-mod-event-group-container"][1] In the picture below, you can see that the above selector will change based upon when the job itself clicks tabs and upon loading the webpage. The webpage has a habit of randomising opened and closed tabs. So this explains why it will click some elements and then completely break or if you add try except, click only some elements and finish.

output:

1
2
3
4
#Stops working

Desired

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

enter image description here The above images are both:

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

You can see how this will cause issues later on. The image on the right would not be able to locate //div[@class="KambiBC-collapsible-container KambiBC-mod-event-group-container"][11] where a the one on the left could based on the order of tabs clicked.

outerhtml

Answer

Rather than using an index to reference these "tabs", you need an alternate way to uniquely identify each one.

One solution is to work with the developers of the site to get them to add an id or name attribute to the "KambiBC-collapsible-container" for each tab.

Another solution, if you're using the Page Object Model approach, would be to create a method on the page that provides a list of the available tabs that you can then reference by the header text. Then you just keep track of which ones you've opened.

Yet another solution would depend on the functionality of the site. You may be able to leverage the fact that if a tab has been opened it looks like the container has a class "KambiBC-expanded". If a tab will stay open until you explicitly close it, you could simply get a list of all of the containers that do not have the "KambiBC-expanded" class and pick one to expand, repeating until there are no more to expand.

https://en.xdnf.cn/q/119441.html

Related Q&A

Xlwings / open password protected worksheet in xlsx?

I get an answer how to open a password protected xlsx with xlwings: Xlwings / open password protected xlsx? wb = xlwings.Book("file.xlsx", password="Passw0rd!")But can i also open …

Wrapping an opencv implementaion of an error level analysis algorithm using cython

i have implemented an error level analysis algorithm using c++(opencv version 2.4) and i want to build a python wrapper for it using cython. I have read some part of the documentation of cython for c++…

Setting yticks Location Matplotlib

Im trying to create a plot which has y axis exactly same with this : And Im in this situation and everything is ok until this point:When i try this lines:ax.set_yticks(range(20,67,10)) ax.set_yticklabe…

How to merge list to become string without adding any character in python?

I found that I can join them with -.join(name) but I dont want to add any character. Lets say I have [stanje1, |, st6, , stanje2, |, #] and I want to be like thisstanje1|st6,stanje2|#

Removing a key from a nested dictionary based on value

I previusly asked about adding, and someone helped me out with append. My new problem is trying to delete a key with a nested list, e.g.:JSON:data = {"result":[{"name":"Teddy&q…

Is dot product and normal multiplication results of 2 numpy arrays same?

I am working with kernel PCA in Python and I have to find the values after projecting the original data to the principal components.I use the equation fv = eigvecs[:,:ncomp]print(len(fv))td = fv.T …

Tkinter Entry widget stays empty in larger programs (Python 2)

I want to make a program where, after clicking on a button, a user gets asked for its name, after which the program continues. Im stuck on making the popup return the textstring that has been entered i…

How do i implement this python tree linked list code in dart?

Here is the python codedef tree(root_label, branches=[]):for branch in branches:assert is_tree(branch), branches must be treesreturn [root_label] + list(branches)def label(tree):return tree[0]def branc…

How can i find the ips in network in python

How can i find the TCP ips in network with the range(i.e 132.32.0.3 to 132.32.0.44) through python programming and also want to know the which ips are alive and which are dead. please send me.. thanks …

Python Coding (call function / return values)

I am having trouble writing code for this question. I have seen this question asked in a few places but I still cannot figure out the answer from the tips they provided. The question is: Write a progr…