Selenium isn't capturing all elements that match my criteria.

13 views
Skip to first unread message

Jay S

unread,
Jun 9, 2023, 10:41:54 PM6/9/23
to Selenium Users
Code:

#! /usr/bin/python3

import selenium
from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Firefox()

iconsgrid = driver.find_element(By.CLASS_NAME, "iif-icons--grid")
icons = iconsgrid.find_elements(By.TAG_NAME, 'a')

for e in icons:
    print(e.text)

It manages to spit out about half of the button names and then prints a bunch of empty strings.

I am trying to automate clicking on each button and downloading each icon from this page:

https://icon-sets.iconify.design/fluent-mdl2/

Any guidance really appreciated.



Raghu Periyasamy

unread,
Jun 10, 2023, 3:24:17 AM6/10/23
to seleniu...@googlegroups.com
Hi Jay,

Here you go with your script...

iconsgrid = driver.find_element(By.CLASS_NAME, "iif-icons--grid")
icons = iconsgrid.find_elements(By.XPATH, '//li/a/iconify-icon')

print(len(icons))

for e in icons:
#print(e.text) --- don't use text here - icons are not having any text
e.click() #click on element
download = driver.find_element(By.XPATH, "//a[text()='Download SVG']")
download.click() #click on Download SVG
time.sleep(1) # wait for a second


 

--

Thanks & Regards,
Raghu P
Python+Selenium Trainer



--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/553619e1-0af7-45b6-aca9-3dd1c72cba98n%40googlegroups.com.

Jay S

unread,
Jun 10, 2023, 2:06:00 PM6/10/23
to Selenium Users
Thanks for the script Raghu P.

Unfortunately it's also not working.

print(len(icons))
is 0. And then the script terminates without doing anything.

Full code:

#! /usr/bin/python3
import time
import selenium
from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Firefox()

iconsgrid = driver.find_element(By.CLASS_NAME, "iif-icons--grid")

icons = iconsgrid.find_elements(By.XPATH, '//li/a/iconify-icon')

print(len(icons))

for e in icons:
    #print(e.text)      --- don't use text here - icons are not having any text
    e.click()  #click on element
    download = driver.find_element(By.XPATH, "//a[text()='Download SVG']")
    download.click() #click on Download SVG

time.sleep(1) # wait for a second
Reply all
Reply to author
Forward
0 new messages