'Clicking through links in Selenium Python
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.
Solution 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()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | undetected Selenium |
