1

I have logged onto a third party website where I have a page full of URLs to click. I was able to collect the elements as such:

for i in num_alphabets:
    names = browser.find_elements(by=By.CLASS_NAME, value='client-name')
print(len(names)) # gives you the number of clients!!!

So now that I have this list called names, I want to know how I can click through all these elements. For now that would be enough, later on I want to have it store some information after clicking. I tried adding .click() at the end and it obviously won't work as names is a list.

Should I maybe create an array with only the first values of the list and then click through that? browser.click() isn't a valid attribute so I don't think that would work.

1 Answer 1

1

Here names is the list of WebElements with value as client-name. So to click on each of those WebElements you have to iterate through the list. Incase the page doesn't changes and the client-name sections are on the same page you can use the following code block:

for name in names:
    name.click()
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you so much! I knew I was missing something very obvious, I couldn't figure out what. This is actually nearly everything that I have to do. The only thing left is a string comparison. Once I click the name, I want to get the element that has the string containing the number of appointments and if it is 1-4, store that name somewhere. Should I create a separate question for this? I tried getting the element and storing but it is giving me empty arrays
@diana18 Seperate ticket please.
I solved it actually my program is ready. Thank you though!!!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.